views:

224

answers:

1

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.

A: 

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

CraigTP