Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The LINQ expression node type 'Lambda' is not supported in LINQ to Entities

I'm trying use Expression and pass to query. But I have error - The LINQ expression node type 'Lambda' is not supported in LINQ to Entities. I'm also used linqkit.dll with AsExpandable(), but but have the same error.

public List<Correct> GetCorrects(Expression<Func<Correct, bool?>> predicate)
{
    using (SystemsEntities context = new SystemsEntities())
    {
        var result = context.Corrects.Where(x => predicate == null);
        return result.ToList();
    }
}

I get the error stated above. What is failing?

like image 332
zrabzdn Avatar asked Dec 23 '13 13:12

zrabzdn


1 Answers

Use this:

var result = context.Corrects.Where(predicate);

instead of this:

var result = context.Corrects.Where(x => predicate == null);

Where expects argument of type Expression<Func<T, bool>>, but you're trying to pass Expression<Func<T, Expression<...>> instead. This is valid compile-time construct, but at run-time LINQ provider fails, when it tries to translate predicate to SQL.

Also note, that you should change Expression<Func<Correct, bool?>> into Expression<Func<Correct, bool>>.

like image 194
Dennis Avatar answered Oct 10 '22 10:10

Dennis