Hi,
I developed an Asp.net application that uses Entity framework to connect to a Sql Server 2008(not R2) database.
The client run the db script against a Sql server 2008 R2 database and it executed successfully.
When the application is executed an exception is thrown:
'Sysutcdatetime' is not recognized as a built in function.
After checking the stack trace, it appeared that the exception is thrown when a LINQ to Entity framework statement is executed. The statement is something like this:
var item = Entities.News.FirstOrDefault(n => n.ExpirationDate > DateTime.UtcNow);
As far as I understand this, the generated sql statement from Entity framework uses the function Sysutcdatetime to get the current UTC date and time.
I know one of the solutions is to store the date in a variable than pass it to the lambda expression, that way the UTC date and time will be determined in the application level and hardcoded in the generated sql statement.
var currentUtcDate = DateTime.UtcNow;
var item = Entities.News.FirstOrDefault(n => n.ExpirationDate > currentUtcDate);
But I am curious why the function Sysutcdatetime exists in Sql server 2008 and not in Sql server 2008 R2 ?