c# - How to group items in a list with the same max date and filter them -
i have list<takenbmi>
these 4 columns , data:
takendate uerid takenitem takenvalue aug-10-2014 34 weight 140 aug-10-2014 34 height 5.5 mar-15-2015 34 weight 141 mar-15-2015 34 height 5.5
i want group them in separate lists based on takendate , find out list should use has details latest taken date.
here have tried:
var q = n in takenbmi group n n.takendate g select g.orderbydescending(t=>t.takendate ) .firstordefault(); var m = n in takenbmi group n n.takendate g select new { takendate = convert.todatetime(q) };
also, if can suggest after getting list max date one, how 2nd latest date ones if possible? thank replied
i'd approach finding latest date:
var latestdate = items.select(i => i.takendate).max();
then filtering items date:
var itemswithlatestdate = items.where(i => i.takendate == latestdate).tolist();
if require of them grouped in date order, then:
var itemsbydate = items.groupby(i => i.takendate).orderby(g => g.key);
the latest date group last of groups:
var itemswithlatestdate = itemsbydate.last();
Comments
Post a Comment