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 props (called requiredprops) need query collection with. want return collection of units satisfy condition of having props 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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -