Help me construct this Linq statement

Posted by Geoffrey on Stack Overflow See other posts from Stack Overflow or by Geoffrey
Published on 2010-04-15T16:05:16Z Indexed on 2010/04/15 16:13 UTC
Read the original article Hit count: 134

Filed under:
|

There should be a simple Linq query for what I'm trying to accomplish, but I'm producing some ugly code.

I have two tables, one of issues and another of issue status. There is a one-to-many relationship between issue and issue status. When an issue is created an IssueStatus is also created with the status field set to "Open" when it is closed, another IssueStatus is created with the status field set to "Closed" ... but issues can be re-opened. It seems like I should be able to write something like this:

    public static List<Issue> FindOpenIssues(this IList<Issue> issues) {
        return (
            from issue in issues
            from issueStatus in issue.issueStatus.OrderBy(x=>x.CreatedOn).Single() 
            where issueStatus.Status == "Open"
            select issue
            ).ToList();
    }

This obviously fails, but there must be a clean way to do this? Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ