3

I have dynamic string generated from back end which generates expression like:

"Col NOT IN ('ABC','CDE','EDF'...)"

I would like to make use of above string has predicate to my IEnumerable collection. Does Dynamic LINQ supports NOT IN operation?

3
  • 1
    I have assumed the ABC CDE and EDF values are contained in a string array i.e. notInArray = ["ABC", "CDE", "EDF"]. Could you not simply do collection = collection.Where(i => !notInArray.Contains(i.Col))? Commented Jan 2, 2018 at 12:39
  • IN is Contains in LINQ: stackoverflow.com/q/15633066/861716 Commented Jan 2, 2018 at 12:49
  • It's not supported directly (in fact Dynamic LINQ supports just a limited set of standard LINQ methods). You have to do parsing yourself. Or modify the backend to generate some more structured query definition instead of string. Commented Jan 3, 2018 at 13:33

2 Answers 2

1

It is possible to do this by using a SQL syntax that is much less common, but does the same thing:

"NOT (Col IN ('ABC','CDE','EDF'...))"

This works both for SQL and Dynamic Linq

Sign up to request clarification or add additional context in comments.

Comments

-1

You didn't provide your sample code but it seems something like;

var array = new [] {"ABD", "ABC", "BED"};
var result = _context.table.Where(x => !array.Any(y => x.Col1 == y));

3 Comments

var result = _context.table.Where(x => !array.Contains(x.Col1));
The question is about Dynamic LINQ.
I would like to implement in Dynamic LINQ not through LINQ. My String will be like "'ABC','DEF','GHI'".....comma separator with more than 15000 characters.

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.