linq - C# Filter List of Objects With a Simple List -


quite new linq here , wondering how achieve this. have following codes:

var allorgs = (from org in this.context.organizations select org).tolist();  var childorgs = (from oc in this.context.organizationchild select oc).tolist();  var parentorgs = (from op in this.context.organizationparent select op).tolist(); 

the return values each variable follows:

allorgs = [{id=1}, {id=2}, {id=3}, {id=4}]; childorgs = [{id=2}]; parentorgs = [{id=3}]; 

i want filter allorgs such items not in childorgs or parentorgs returned, i.e.

filteredlist = [{id=1}, {id=4}]; 

i have following linq filter (which need with):

var filteredlist = allorgs.where(a => childorgs.any(c => c.id != a.id));  filteredlist = filteredlist.where(f => parentorgs.any(p => p.id != f.id));  return filteredlist.tolist(); 

for reason, still end getting values...

appreciate insight. thanks!

just merge 2 conditions:

filteredlist = allorgs.where(a => !childorgs.any(c => c.id == a.id)                                && !parentorgs.any(c => c.id == a.id)                              ); 

note original query backwards - looking orgs any parent or child org doesn't match.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -