我正在尝试动态创建以下WHERE子句表达式:
context.Cars.
Where(c => EntityFunctions.DiffDays(c.Created, c.Created) == null).
ToList()
这是我用来创建表达式的代码:
var parameter = Expression.Parameter(typeof(Car), "c");
var property = Expression.Property(parameter, "Created");
var function = Expression.Call(typeof(EntityFunctions), "DiffDays",
null, property, property);
var comparison = Expression.Equal(function, Expression.Constant(null));
var result = Expression.Lamda<Func<Car, bool>>(comparison, parameter);
结果显示(它似乎缺少“EntityFunctions.DiffDays”):
{c => (DiffDays(c.Created, c.Created) == null)}
当我尝试执行时:
context.Cars.Where(result.Compile()).ToList()
我收到错误消息:
只能从调用此函数
实体的Linq
你知道我错过了什么吗?是因为它只显示“datediff”而不是“entityfunctions.datediff”
谢谢。亚当