c# - LINQ correlated subqueries -


starting next entities definition:

public class certificate{   public  id int; }  public class authority{   id int;   certificates ienumerable<certificate>; } 

my function recives 2 collections: ienumerable<certificate> , ienumerable<authority>. need select authorities certificates collection has @ least 1 certificate in ienumerable<certificate> input parameter.

my firt implementation enumerating ienumerable<certificate> , selecting authority using where(predicate).

public ienumerable<authority> selectauthorities(authlist ienumerable<authority>, certlist ienumerable<certificate>){    foreach (certificate loadedcert in certlist) {     yield return auth.where(a => a.certificados.any(c1 => c1.idcert == loadedcert.idcert));   }    } 

i think there must way avoid loop using more complex linq correlated subquery (i feel in "force") can't find it.

can help?

you can use double any avoid loop:

authlist.where(a => a.certificados                      .any(c1 => certlist.any(c2 => c1.idcert == c2.idcert))); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -