Correct way to write a LINQ or Lambda to retrieve items with a matching supplier ID
Given the following classes
Product
- int ProductID - Supplier[] Suppliers ...Supplier
- int SupplierID - string SupplierName ...If I have an array of 1000 products, an开发者_如何转开发d each product can contain multiple suppliers, how would I get supplier ID [X] from the array of Products?
var suppliers = 
    from product in products
    from supplier in product.Suppliers
    where supplier.SupplierID == X
    select supplier;
Or use the extension method equivalent:
var suppliers = 
    products.SelectMany(p => p.Suppliers).Where(s => s.SupplierID == X);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论