c# - Query which returns results only if all (non-primitive) values from a compared enumerable are contained in the target enumerable -
we have collection of entities of type called unit, collection of entities of type unitprop , collection of entities of type called prop defined (simplified):
class unit { int id; icollection<unitprop> unitprops; } class unitprop { int id; int unitid; unit unit; int propid; prop prop; } class prop { int id; string description; }
we have list
of prop
s (called requiredprops) need query collection with. want return collection of unit
s satisfy condition of having prop
s specified in requiredprops.
i wrote query this:
var result = ctx.units .where(x => requiredprops.asenumerable() .except(x.unitprops.select(y => y.prop)) .count() == 0) .tolist();
of course, linq entities query throw exception: unable create constant value of type 'prop'. primitive types ('such int32, string, , guid') supported in context.
i tried this:
var result = ctx.units .where(x => requiredprops.select(y => y.id) .except(x.unitprops .select(y => y.prop) .select(y => y.id)) .count() == 0) .tolist();
...but yielded same exception.
suggestions?
var requiredids = requiredprops.select(y => y.id); var result = ctx.units .where(m => !requiredids .except(m.unitprops.select(x => x.prop.id))) .any()) .tolist();
Comments
Post a Comment