我想使用的EntityFramework執行Linq查詢,並得到錯誤LINQ到實體無法識別方法EntityFunctions.DiffMonths
System.NotSupportedException: LINQ to Entities does not recognize the method 'System.Nullable`1[System.Int32] DiffMonths(System.Nullable`1[System.DateTime], System.Nullable`1[System.DateTime])' method, and this method cannot be translated into a store expression.
代碼
public bool FreeConversionExceeded(string ip)
{
var count = _statisticRepository.GetAll().Count(p => p.Ip == ip && EntityFunctions.DiffMonths(DateTime.UtcNow, p.DateStamp) == 0);
return count > 200;
}
public IQueryable<Statistic> GetAll()
{
return _context.Statistic;
}
我只是不明白爲什麼EntityFunctions.DiffMonths
不管用。從幫助文件「This function is translated to a corresponding function in the database.
」,所以它應該工作?
無法重現此操作,它使用'DateTime'和'DateTime?'列。 –
我也不明白爲什麼它不起作用。它在我以前的項目中運行良好,我找不到原因! – Tomas