I'm trying to use a contains in a list within a list but been stuck on this one:
var postFilter = PredicateBuilder.False<Company>();
// Loop through each word and see if it's in the company's facility
foreach (var term in splitSearch)
{
var sTerm = term.Trim();
postFilter = postFilter.Or(x =>
x.Facilities.Contains(y=>
y.Facility.Name.ToUpper().Contains(sTerm)) ||
x => x.Facilities.Contains(y =>
y.Facility.Description.ToUpper().Contains(sTerm)));
}
Postfilter is a list of companies, a company has a list of companyfacility items which is a 1:m relationship. A facility also has a 1:m relationship with this table. The x thus represents a companyfacility object. The y should represent a facility object.
(So a company can have many facilities, and a facility can belong to many companies. In between i use the companyfacility table for additional information of that companies facility - example, a specific company can have a lathe table that goes to diameter 300 where other companies would go to diameter 250, so it's important to have the table in between)
I want to return the companies which have the sTerm in their facility name or facility description, but this linq statement is invalid.
Thanks for the help!
xandyin nested lambdas. You can easily usecompanyandfacilityas identifiers.