Newest price for an item in LINQ / LAMBDA
How do I formulate the following in LINQ with LAMBDA expressions.
Given (for simplicity - this is actually later a join) a table with the fields:
- Item
- Price
- Timestamp
which is mapped to a class. I use BlToolkit, but could also be LINQ or EF - makes no difference.
I want the object with Item = 2 and the highest timestamp (newest) and / or a query of ALL items but ONLY the most current 开发者_JAVA百科object.
How do I formulate this?
I understand there will likely be a subselect involved, but I have a problem finding the correct syntax.
Using fluent syntax, the item with the highest timestamp, and Item==2
is:
var item= table.Where(i => i.Item == 2)
.OrderByDescending(i => i.Timestamp)
.SingleOrDefault();
精彩评论