Dynamic linQ on string array

arrays dynamic-linq

Question

This is a string array I have.

string[] ColumnArray = new string[] { First story, second data , third way };

The linQ query for this array is shown below.

string query = (from x in ColumnArray 
                           where x.Contains("Story")
                            select x).First();

But sometimes, the question will look like this.

string query = (from x in ColumnArray 
                         where ( x.Contains("Story") || x.Contains("View"))
                         select x).First();

That prerequisite ought to add dynamically. How dynamic LinQ can assist in this situation.

I've written something similar before.

string dynamiccondition= // some condition.

 var query = (from x in ColumnArray.AsEnumerable().AsQueryable().Where(dynamiccondition).Select(x));

/ nevertheless, this is ineffective.

Any recommendations?

1
0
1/29/2014 1:51:43 PM

Accepted Answer

In DynamicLINQ Utilize logical operations such asAND(&&) and OR(||) so try something similar.

string dynamiccondition="it.Contains(\"Story\") OR it.Contains(\"View\")"

var query = ColumnArray.AsQueryable()
                       .Where(dynamiccondition);
1
1/29/2014 2:21:52 PM


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