Results 1 to 2 of 2

Thread: [RESOLVED] Help optimising LINQ query is needed

Threaded View

  1. #1

    Thread Starter
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Resolved [RESOLVED] Help optimising LINQ query is needed

    I've a class
    Code:
    Class DeclInfo
    {
         public int Year {get; set;}
         public int Quarter {get; set;}
         public int CorrectionNumber {get; set;}
         // ...
    } // class DeclInfo
    I'm writing a method FindFirst which queries a collection of DeclInfo to find an earliest instance:
    Find earliest year, then find earliest quarter and then find the latest (max) correction number.

    Now I have the following:
    Code:
    int Criteria = allDecls.Min(d => d.Year);
    allDecls = allDecls.Where(d => d.Year == Criteria).ToList();
    Criteria = allDecls.Min(d => d.Quarter);
    allDecls = allDecls.Where(d => d.Quarter == Criteria).ToList();
    Criteria = allDecls.Max(d => d.CorrectionNumber);
    di = allDecls.First(d => d.CorrectionNumber == Criteria);
    I don't like what I see very much and therefore - a question - is there a way to make it simpler?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width