Я пытаюсь выполнить запрос Linq в использовании EntityFramework и получить ошибкуLINQ к Entities не распознает метод 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