Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:03:57+00:00 2026-05-14T09:03:57+00:00

There should be a simple Linq query for what I’m trying to accomplish, but

  • 0

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.OrderByDescending(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!

Edit: As Reed Copsey points out, my intention is to find current open issues. An issue might contain an element “Open” and at a later date, an element “Closed” … which is why a simple Where == “Open” won’t work, it needs to find the element with the most recent date in the list to determine the status of the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:03:58+00:00Added an answer on May 14, 2026 at 9:03 am

    It looks like you’re trying to find issues with a status marked “Open”. If so, this should work:

    public static List<Issue> FindOpenIssues(this IList<Issue> issues) {
        return issues
                  .Where(i => i.issueStatus.Any(stat => stat.Status == "Open")
                  .ToList();
    }
    

    This is different from your original, but based on the method name, I believe may actually provide the intended results (any issues where there is a status of Open).

    You can do what would be returned by your original like so:

    public static List<Issue> FindOpenIssues(this IList<Issue> issues) {
        return issues
                .Where(i => i.issueStatus
                                 // This potentially should be (I left your original logic, though):
                                 // .OrderByDescending(stat => stat.CreatedOn)
                                 .OrderBy(stat => stat.CreatedOn)
                                 .First()
                                 .Status == "Open"
                      )
                .ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple linq query that unionizes two tables that implement the same
I know there should be a simple fix for this, but im braindead at
This should be simple, but I am still lost. There is a very similar
I'm refactoring this code and was trying to think of a simple linq expression
I am fairly new to Linq To SQL but trying to run what should
How can I do a Linq query for this? I have two xml documents,
I would assume there's a simple LINQ query to do this, I'm just not
This should be very simple question. There are many programming languages out there, compiled
Is there a simple description of how the dictionary file in Proguard should be
I'm fairly sure there should be an elegant solution to this (in MATLAB), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.