I have seen grouping examples to get sum or other aggregate function outputs, but i am stuck in trying to get the “record” which matches a grouped criteria, i do not need a aggregate value. Let me explain my situation:
Im using LINQ to EF, I have a table, Entity_Revisions with columns Entity_Id, Entity_Revision_Number and lots of other columns. The Entity_Revision_Number is like a version of the entity. So i want a LINQ query to give me the latest version. Below is the kind of data:
Entity_Id Entity_Revision_Number
1 0
1 1
2 0
3 0
3 1
I need a query that returns records 1,1 2,0 and 3,1. The query i would need is kind of
from e in ENTITY_REVISIONs
<some joins>
<some where>
group e by e.ENTITY_ID into g
select g <where max(g.entity_revision_number)>
Also is it possible to get the ENTITY_REVISIONs type as output and not in the form of new{} annonymous type?
Group by id, order each group descending by revision number, and get first value of each group should be fine :