Question

I have a string array like this.

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

Following is the linQ query on this array.

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

But sometimes the query will be like this.

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

That condition should add dynamically. SO how the dynamic LinQ can helps here.

I have written something like this.

string dynamiccondition= // some condition.

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

// but this is not working.

Any suggestion?

Was it helpful?

Solution

In DynamicLINQ you can use logical operation like AND(&&) and OR(||), so try something like this

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

var query = ColumnArray.AsQueryable()
                       .Where(dynamiccondition);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top