2
我想創建以下WHERE子句動態表情:動態創建一個表達式調用方法EntityFunctions.DiffDays
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」
謝謝。亞當