Dynamic Linq gives error in combination with EntityFramework

c# dynamic-linq entity-framework linq linq-to-entities

Question

We use Entity Framework, and we need some runtime build queries on our objects. Building expression trees from scratch seems like a lot of work, so we want to use "System.Linq.Dynamic"

Working through the samples I got this to work:

dbModel.As.Where("AStuff.Contains(@0) OR AStuff.Contains(@1)","ac","bc")

But if I try to build the expressions seperately like this:

    Expression<Func<A, bool>> predicateA =
        DynamicExpression.ParseLambda<A, bool>(                    
            "AStuff.Contains(@0)",
            "ac"
        );

    Expression<Func<A,bool>> predicateB =
        DynamicExpression.ParseLambda<A, bool>(
            "AStuff.Contains(@0)",
            "bc"
        );

    dbModel.As.Where("@0(it) OR @1(it)", predicateA, predicateB);

it explodes with an exception: NotSupportedException>>The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.

It may be possible to build the entire query in the first form, but the later would be more useful in our scenario. Is there a way to make that work?

1
1
1/13/2014 10:08:54 AM

Popular Answer

Just use Predicate Builder to join (Or/And) multiple predicates.

0
1/30/2014 9:50:42 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow