c# - groupby filtering in linq -
i need groupby query
if (randomize) { list<tblinvoice> _result = db.tblinvoices.tolist(); var _temp = xxx.where(p => (p.ispostalpayment == null || p.ispostalpayment == false)).tolist(); _result = _temp.orderby(o => guid.newguid()).take(5).tolist(); _result = _result.groupby(x => x.cuserid).tolist(); return _result; }
when use groupby in query, error when use groupby in query, under error
cannot implicitly convert type 'system.collections.generic.list>' 'system.collections.generic.list'
the type of _result
list<tblinvoice>
. here
_result = _temp.orderby(o => guid.newguid()).take(5).tolist();
you have no problem. order invoices , take 5 of them create new list<tblinvoice>
.
however, here
_result = _result.groupby(x => x.cuserid).tolist();
there problem. groupby
return sequence of igrouping<tkey,telement>
objects , calling tolist
create list of type of objects , not list<tblinvoice>
. can't assign reference of list of type variable can hold references list<tblinvoice>
objects.
Comments
Post a Comment