Reputation: 1813
I have a problem with LINQ query. Could somebody please help?
There is one table Content with Columns Id (unique), ContentId, Version. I'd like to get the latest version for each unique Content Id.
So if table is:
- Id, ContentId, Version
- 1, 1, 1
- 2, 1, 2
- 3, 2, 1
Then query should return:
- Id, ContentId, Version
- 2, 1, 2
- 3, 2, 1
Upvotes: 0
Views: 42
Reputation: 31239
Maybe something like this:
var result= (
from c in db.Content
where db.Content
.Where (l =>l.ContentId==c.ContentId)
.Max (l=>l.Version)==c.Version
select c
);
Where db is the linq data context
Upvotes: 1