Oops, read the question incorrectly:
var matchingOrders = from customer in customers from order in customer.Orders where order.ID == orderID select order; var order = matchingOrders.Single();
As with the earlier version of this answer, note that this will fail if there are no such matches or more than one. You can also look at SingleOrDefault , First and FirstOrDefault .
This code can also be written without query expressions using SelectMany :
var order = customers.SelectMany(customer => customer.Orders) .Single(order => order.ID == orderID);
Note that you do not need to use Where , and then Single - there Single overloads using the predicate (as well as for FirstOrDefault , etc.). It doesn't matter if you use a query expression form or not, I usually use query expressions rather than SelectMany , but in this case you don't need a client, so you can use SelectMany simple overloading.
source share