Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlMethods.DateDiffMonth in the Entity Framework

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

This is the error I am getting when I tried to use it.

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


1 Answers

It would appear that, currently, you need to express this using an eSQL statement that effectively calls down to the SQLServer DATEDIFF method

For example:

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

(See here for further info)

However, when the .NET Framework Version 4.0 is released (or you can use it now if you like playing with beta software! :) you should be able to use the DateDiff method of the new SqlFunctions class, which is part of the new System.Data.Objects.SqlClient Namespace in .NET 4.0

like image 183
CraigTP Avatar answered Dec 22 '25 20:12

CraigTP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!