c# - How to select last record in a LINQ GroupBy clause -


i have following simple table id, contactid , comment.

enter image description here

i want select records , groupby contactid. used linq extension method statement:

mains.groupby(l => l.contactid)  .select(g => g.firstordefault())  .tolist() 

it returns record 1 , 4. how can use linq contactid highest id? (i.e. return 3 , 6)

you can order items

mains.groupby(l => l.contactid) .select(g=>g.orderbydescending(c=>c.id).firstordefault())  .tolist() 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -