0

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?

Dev
  • 309
  • 1
  • 8
  • 24
  • what condition you try? What you meant not working? it raise exception or not filter? – Grundy Jan 29 '14 at 13:57
  • condition may be something like this string dynamiccondition = "x.Contains('Story') || x.Contains('view')"; -- > but I am not sure how to write dynamic linQ on string array. What i need is to get the string which contain any of these values(I need to make the condition using dynamic linQ) . – Dev Jan 29 '14 at 14:15
  • try see more on [official page](http://dynamiclinq.codeplex.com/documentation) – Grundy Jan 30 '14 at 05:02

1 Answers1

1

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);
Grundy
  • 13,356
  • 3
  • 35
  • 55