LINQ node expression of type "Lambda" is not supported in LINQ to Entities

I am trying to use an expression and pass a request. But I have a mistake - LINQ node expression of type Lambda is not supported in LINQ to Entities. I also use linqkit.dll with AsExpandable (), but I 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 above. What is failing?

+8
c # linq entity-framework
source share
1 answer

Use this:

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

instead of this:

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

Where expects an argument of type Expression<Func<T, bool>> , but instead you are trying to pass Expression<Func<T, Expression<...>> . This is a valid compile time construct, but the LINQ provider fails when it tries to translate predicate into SQL.

Also note that you must change Expression<Func<Correct, bool?>> to Expression<Func<Correct, bool>> .

+14
source share

All Articles