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?

3
  • what condition you try? What you meant not working? it raise exception or not filter? Commented Jan 29, 2014 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) . Commented Jan 29, 2014 at 14:15
  • try see more on official page Commented Jan 30, 2014 at 5:02

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.