c# - Filter a given List based on external List in Linq in one query -
i've list :
list<student> lststudents = getconditionalstudents();
i've list:
list<school> allschools = dbcontext.schools.tolist();
every school has list of students
public class school { ///other properties public list<student> {get;set;} }
i'am forced this:
list<school> schools = p in allschools p.locationid==this.locationid p.students.any(d=>lststudents.contains(d)) select p;
but doesn't work: gives error
unable create constant value .. primitive types
edit i can create work doing this:
list<int> integers = lststudents.select(s=>s.id).tolist(); list<school> schools = p in allschools p.locationid == this.locationid p.students.any(d=>integers.contains(d.id)) select p;
but don't want utilize it, coz hav situations have compare more 2 ids, implies, have create more 2 separate primitive datatype list
, utilize them in query,which don't want.
how straight utilize external list in linq query.??
i cannot utilize this:
allschools.where(s=>s.locationid==this.locationid || lststudents.contains(s)).tolist();
please help... went through this , this..but no help me..
try:
var schools = p in allschools (p.locationid==this.locationid && p.students.any(s => lststudents.contains(s))) select p;
c# linq entity-framework ef-code-first sql-server-ce
No comments:
Post a Comment