how to filter with array/list via dynamic linq

.net dynamic-linq

Question

Hell all!

I tried all known variations to filter with Contains, but so far no luck.

METHOD #1

ret = ret.Where("CaseID.Contains(@0)", {15, 16, 17})

Gets the following error:

System.Linq.Dynamic.ParseException: 'No applicable method 'Contains' exists in type 'Int32?''

METHOD #2

ret.Where("@0.Contains(outerIt.CaseID)", {15, 16, 17})

Bring the following error:

System.Linq.Dynamic.ParseException: 'No 'it' is in scope'

So, how can i filter by a list or array?

I'm using the latest System.Linq.Dynamic library in nuget 1.0.7

1
1
8/28/2017 1:15:03 PM

Accepted Answer

the following will work, but you must to ensure that the CaseID and the array values have the same Type.

ret.Where("@0.Any(outerIt.CaseID=it)", array)

3
8/29/2017 10:15:01 AM

Popular Answer

Not quite sure if I understand your question right. But do you mean something like this? This is solved with a Lambda-Expression.

var listA = new[] {1, 2, 3, 5, 8};
var listB = new[] {1, 3, 5, 7, 11};
var res = listA.Where(itemA => listB.Contains(itemA));
// res = {1,3,5}


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