简体   繁体   中英

EF5 Select objects based on child collection content

I have the following case:

public Order
{
    ICollection<OrderItems> OrderItems {get; set;}
}

public OrderItem
{
    ICollection<ProductReferences> ProdReferences {get; set;}
}

and I want to get a collection of all the orders that have a particular product, eg something like:

Orders.Where(o=>o.OrderItems.Any(oi=>oi.Name.Equals(someName))).ToList();

But I want to go one level deeper. As in:

Orders.Where(o=>o.OrderItems.Any(oi=>oi.ProdReferences.Any(pr=>pr.Name.Equals(someName)))).ToList();

Any help is appreciated.

try:

Orders.Where(
    o => o.OrderItems.Any(
        oi => oi.ProdReferences.Any(
            pr => pr.Name.Contains(someName))));

ie, replace pr.Name.Equals with pr.Name.Contains .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM