When I run this piece of code:
string[] words = new string[] { "foo", "bar" };
var results = from row in Assets select row;
foreach (string word in words)
{
results = results.Where(row => row.Name.Contains(word));
}
I get this SQL:
DECLARE @p0 VarChar(5) = '%bar%'
DECLARE @p1 VarChar(5) = '%bar%'
SELECT ... FROM [Assets] AS [t0]
WHERE ([t0].[Name] LIKE @p0) AND ([t0].[Name] LIKE @p1)
Please note that @p0and @p1are barwhen I wanted them to be fooand bar.
I assume that Linq somehow binds a link to a variable word, and not a link to a string that is currently referenced word? What is the best way to avoid this problem?
(Also, if you have suggestions for improving the title for this question, post it in the comments.)
Notice that I tried this with regular Linq also with the same results (you can paste this directly into Linqpad):
string[] words = new string[] { "f", "a" };
string[] dictionary = new string[] { "foo", "bar", "jack", "splat" };
var results = from row in dictionary select row;
foreach (string word in words)
{
results = results.Where(row => row.Contains(word));
}
results.Dump();
Spleen:
bar
jack
splat