0

I have used Dynamic Linq in my application and unfortunately it's not working. Here is my sample code.

List<string> contains = new List<string>() { "Poland", "Ecuador" };
List<object> array = new List<object>();
array.Add("Austria");
array.Add("Eritrea");
array.Add(contains);

//this works
var data0 = Contact.GetContactsList().AsQueryable().Where("@0.Contains(outerIt.Country)", array);

//this does not work
var data = Contact.GetContactsList().AsQueryable().Where("Country.Equals(@0) OR it.Country.Equals(@1) OR @3.Contains(outerIt.Country)", array.ToArray());

I have list of contacts related with countries. You can see that I have used mixed operators i.e equals and contains. If contains is used separately then it works which is correct. I tried to do new thing here, using both Equals and Contains operators is same query string. I have attached am image describing output or data0 and error while processing to get data

enter image description here

Thank You.

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
KNIGHT
  • 11
  • 3
  • When you created array as `List` and than add to it `contains` you end up with an list that has first two elements that are strings "Austria" , "Eritrea" and a third element which is itself a list with 2 strings in it. That seems strange and probably not what you meant to do. Also the queries you wrote does not reference the data sample you sent so it makes it hard to know what is the problem with your query. maybe send a sample with the actual data types you query against? – omer schleifer Jan 09 '17 at 08:16
  • Looks like a simple typo - `@3` should be `@2`. – Ivan Stoev Jan 09 '17 at 08:44

1 Answers1

0

I made a silly mistake there. The code is working fine but I gave wrong index there. Index 3 should be replaced with 2. :P enter image description here

The result is attached.

KNIGHT
  • 11
  • 3