I am having some trouble with a linq query
var matches = from po in purchaseOrders
from poItem in po.Items
where TestMatch(poItem)
select new Item(poItem);
purchaseOrders is a List
Each PurchaseOrder contains a List
What I need for a result, is the first poItem that matches (based on the result of TestMatch(poItem)) in each purchase order, OR a blank Item object.
So that in the end matches.Count == purchaseOrders.Count
Currently, I only get items that match in a PO, and I’m not sure how to ensure I only get ONE item per PO. And I don’t know how to ensure if there is no match, that I get a blank Item for that PO.
It sounds like you want something like:
With C# 4 you can use a method group conversion for the argument to FirstOrDefault: