How to use DynamicLinq "contains” or “like” with numbers?

dynamic-linq linq

Question

Tried this:

.Where("MyColumnID.Contains(@0)", myArray)

But what i got was:

No applicable method 'Contains' exists in type 'Int32'

Any other ways? Something like SqlMethods.Like, but in DynamicLinq?

1
2
1/28/2014 3:05:12 PM

Popular Answer

The Contains() operator works the other way around: It's the array which contains the number, thus it should read as follows:

"@0.Contains(MyColumnID)"

I am however, not sure if this is even possible within DynamicLinq. This other SO question deals with the same problem:

Query data using "Contains" keyword in Dynamic Linq in C#

It suggests the following should work:

int[] CandidateIdsArray = new int[]{4, 78, 101}
var dynamicLinqQuery = 
    Candidates.Where("@0.Contains(CandidateId)", CandidateIdsArray);
2
5/23/2017 11:43:22 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow