Typically a dynamic linq query with string can use a substitution value such as:
result =
db.Persons.Where("Name == @1", "John");
I have an unknown number of strings that I want to pass into the Where clause. I have no problem with integers, but the API cannot seem to handle a string without a substitution value.
Does anyone know a way around this? I created a concatenated string for my Where statement, so I can add “@1” or whatever, but I cannot add parameters to the Where() so I am stuck.
Thanks!
Yes, you can. The second argument of the
Wheremethod isparams object[] values, so you just need to pass an array of objects.For instance, assuming you have the property names and values in a dictionary, you could do something like this: