Search code examples
c#entity-frameworkexpression-trees

How to build dynamic query by expression in c#


First, I have a variable like below:

List<string> values;

Now I need build query condition like below:

Expression<Func<docinstance, bool>> filter = d=>d.values.any(o=>o.value==values[0]||o.value==value[1]||.....)

Because I don't know how many items in variable values, so how can I build the query condition


Solution

  • You can use Any again inside

    d => d.values.Any(o => values.Any(x => x == o.value))