Reputation: 329
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?
Upvotes: 0
Views: 1109
Reputation: 13381
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);
Upvotes: 1