I'm trying to filter an IEnumerable using some of its nested properties.
I've racked my brain every which way but cannot find a solution to this query. In fact I don't event know whether this is possible.
Its structure is like this
T is a Deal a Deal has a collection of Subcategories (the collection may be empty) a Subcategory has a SubcategoryId
I want to be able to select Deals whether they have a SubcategoryId = parameter that is passed to method.
public IEnumerable<Deal> FindDeals(IEnumerable<Deal> source, int subCategoryId)
{
return source.Where(d => d.Subcategories.Any(s => s.Id == subCategoryId));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With