This is likely a novice question about LINQ, but assuming I have a set of Items with a DateTime property, one date having at most one item, how would I go about selecting the N most recent items from a date of reference, that is, the N items which have a date smaller that the requested date, and the largest date?
My naive thought would be to first select items with a date smaller than the reference date, sort by date, and select the N first items from that subset.
var recentItems = from item in dataContext.Items
where item.Date<=date
orderby item.Date descending
select item;
var mostRecentItems = recentItems.Take(5).ToList();
Is this the "right" way to do it, or are there obviously better ways to achieve my goal?