Clients where OrderIds in the child collection are a subset of the identifiers in the collection in memory.
from c in myDC.Customer where c.Orders.All(o => myList.Contains(o.ID)) select c;
Clients where OrderIds in the in-memory collection is a subset of the identifiers in the child collection.
from c in myDC.Customers where (from o in c.Orders where myList.Contains(o.ID) group o.ID by o.ID).Distinct().Count() == myList.Count() select c;
Clients where OrderIds in the in-memory collection are set equal to identifiers in the child collection.
from c in myDC.Customers let Ids = c.Orders.Select(o => o.ID).Distinct() where Ids.Count() == myList.Count() && Ids.All(id => myList.Contains(id)) select c;
All these generated sql for me.
PS - they assume that the identifiers are already allocated in myList. If they are not already installed, use:
myList = myList.Distinct().ToList();
PSS - Suitable for lists of up to ~ 2000 items. Higher than this will be translated into sql, and then the sql server will be barf according to the number of parameters.
Amy b source share