I have a requirement to create a linq query that selects data from a database table where a certain functional result is true.
I am using linq-to-sql and the function works well and I can write a basic query to get the data.
My issue is that I have an in-memory list of parameters and I essentially need to run the linq query multiple times (once for every parameter list item) and aggregate the results.
I have tried using the .Any() as a join but linq doesn’t like joining non-database result sets with database result sets.
Some Sample Code:
Parameter list: // lets call it "l"
{
One,
Two,
Three
}
Query
From w in words where funcWord(l.item) == true select w;
So I would require a query that can run the above query once for every item in l and aggregate the results.
Any help is appreciated.
Thanks.
Try SelectMany, which aggregates the result of a one-to-many function, applied to each member.
In this case, the members are the elements of
list, and the one-to-many function is your above,l-dependent query (though I rewrote it as a lambda function.)list.SelectMany(l => words.Where(w => funcWord(l.item, w.name)));