SqlMethods.DateDiffMonth in Entity Framework

Does anyone know what is a replacement for SqlMethods.DateDiffMonth in the Entity Framework.

This is the error I get when I try to use it.

LINQ to Entities does not recognize the method 'Int32 DateDiffMonth (System.DateTime, System.DateTime)', and this method cannot be translated into a storage expression.

+3
source share
2 answers

It looks like you currently need to express this using an eSQL statement that effectively calls the SQLServer DATEDIFF method

For example:

db.entity.Where("SqlServer.DATEDIFF('MONTH', [start date], [end date]) = 1");

(see here for more information)

, .NET Framework 4.0 ( , - !:), DateDiff SqlFunctions, System.Data.Objects.SqlClient Namespace .NET 4.0

+2

LINQ to Entities, :

var query = query.Where(e => DateTime.Today >= EntityFunctions.TruncateTime(e.StartDateTime)
&& DateTime.Today <= EntityFunctions.TruncateTime(e.EndDateTime));
0

Source: https://habr.com/ru/post/1703013/


All Articles