Looking up values in two different tables with LinqToSQL, and combining the results based on what is found in what resultset.
How can I combine two Funcs based on given conditions:
// a filter for a LinqToSQL query:
Func<ComputerDetail, bool> filter;
// declare the default filter
filter = x => x.ComputerName.Contains(searchTerm);
then if a condition is met it would like to add the below lambda to the above one:
x => computernames.Contains(x.ComputerName)
so it both would result in:
x => computernames.Contains(x.ComputerName)) ||
x.ComputerName.Contains(searchTerm);
Creating a multicast delegate with a plus operator almost seems to do it,
however, I am not sure how to apply the OR (||) in this case:
filter += computernames.Contains(x.ComputerName)
note: computernames is a List<String> , ComputerName is a property of ComputerDetail which is a Class representing a View in LinqToSQL
If it’s LINQ to SQL, you don’t want to combine two delegates – you want to combine two expression trees. Otherwise all of your filtering will be done on the client side.
If that’s the case, I believe you basically just need
PredicateBuilder– usepredicate1.Or(predicate2)to combine two predicates.If you really want the delegate form, you can take the same code and just change all the signatures to use delegates instead of expression trees.