To do this, there must be one liner, and I just can not find it.
Given this request:
from x in new XPQuery<XPContent>(s)
select new { x.Category, x.ContentType, x.Name, x.ContentID, x.Date }
I need to select the record with the highest date for each individual ContentID. Can this be done using LINQ? Now I am doing this:
var q = (from x in new XPQuery<XPContent>(s)
select new { x.Category, x.ContentType, x.Name, x.ContentID, x.Date }).ToList();
var r = q.ToLookup(item => item.ContentID);
foreach (var rItem in r) {
var s = rItem.OrderByDescending(a => a.Date).First();
}
... but ToLookup feels awkward. Or do I have the best (easiest) solution?
In addition, I know that I should not use ToList, but please just ignore it for now.
Thanks in advance!
source
share