Linq - Get last entry from different customers -
i try create linq query unfortunately have no ideas resolve problem. highest entry of customers , form result 5 entries sort date.
id date id_costumer 1 - 01.01.2014 - 1 2 - 02.01.2014 - 2 3 - 02.01.2014 - 1 4 - 03.01.2014 - 1 --> value 5 - 04.01.2014 - 3 6 - 05.01.2014 - 3 --> value 7 - 05.01.2014 - 4 8 - 06.01.2014 - 4 --> value 9 - 08.01.2014 - 5 --> value 10 - 09.01.2014 - 6 --> value
i try query
var query = g in context.geraete g.online && g.altgeraet == false select g; query.groupby(g => g.id_anbieter).select(g => g.last()); query.take(5);
but doesn't work.
you should assign results of selecting last item group query
variable:
query = query.groupby(g => g.id_anbieter).select(g => g.last()); var result = query.take(5);
keep in mind - operator last()
not supported linq entities. think should add ordering when selecting latest item each group, , selecting top 5 latest items:
var query = g in context.geraete g.online && !g.altgeraet group g g.id_anbieter grp select grp.orderbydescending(g => g.date).first(); var result = query.orderbydescending(x => x.date).take(5);
Comments
Post a Comment