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

  • Home
  • SEARCH
  • 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 8546883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:08:16+00:00 2026-06-11T13:08:16+00:00

I have the following IList<Project> projects = (from update in dbContext.TicketUpdates where update.TicketUpdatesEmployeeID ==

  • 0

I have the following

IList<Project> projects = (from update in dbContext.TicketUpdates
               where update.TicketUpdatesEmployeeID == Profile.EmployeeID
               orderby update.TicketUpdatesEndDate descending
               select update.Ticket.Project).Distinct().ToList();

I understand that Distinct() doesn’t guarantee order, but I can’t reorder it afterwards because the projection loses the field I”m using to order. How can I work around this?

  • 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-06-11T13:08:18+00:00Added an answer on June 11, 2026 at 1:08 pm

    I think your best bet is to post process to preserve ordering:

    var projects = (from update in dbContext.TicketUpdates
               where update.TicketUpdatesEmployeeID == Profile.EmployeeID
               orderby update.TicketUpdatesEndDate descending
               select update.Ticket.Project);
    var seen = new HashSet<Project>();
    foreach (var project in projects)
    {
        if (seen.Add(project))
        {
            // A distinct project
        }
    }
    

    Or you could abuse GroupBy:

    var projects = dbContext.TicketUpdates
        .Where(uu => uu.TicketUpdatesEmployeeID == Profile.EmployeeID)
        .GroupBy(uu => uu.Ticket.Project)
        .OrderByDescending(gg => gg.Max(uu => uu.TicketUpdatesEndDate))
        .Select(gg => gg.Key);
    

    By using GroupBy across uu.Ticket.Project each update will be grouped by their associated project. If you have 10 projects and 30 updates spread amongst them, you’ll have 10 groups–one per project–in the output of that stage. Next, we order the groups by their newest end date which preserves the descending order you were looking for. Finally, we select the key from each IGrouping which is the project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public IList<Reference.Grid> GetGrid(string pk) { return ( from d
I have the following code: public static IList<SortOption> SortValues() { var sortValues = (from
I have the following interface declarations: interface IOrder<T> where T: IOrderItem { IList<T> Items
I have a model like the following one: public class TestModel{ public IList<Field> Fields
I have something that looks like the following: var someList = MockRepository.GenerateStub<IList<ISomething>>(); someList.Add(MockRepository.GenerateStub<ISomething>()); The
Here I have the following bit of code: private IList<IState> _states = new List<IState>();
I have a generic dictonary which is templated in the following manner: Dictionary<object, IList<ISomeInterface>>
I have a problem that I'm working in nHibernate project that have the following
Assuming I have the following list: IList<string> list = new List<string>(); list.Add(Mouse); list.Add(Dinner); list.Add(House);
I have the following code string idName = builder.IdentifierName; Disjunction disjunction = Restrictions.Disjunction(); IList

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.