Thursday, March 16, 2017

DbFunctions class of Entity Framework.

Playing with date time in both dotnet and sql server (t-sql) is always challenging and painful for me. Sometimes I forget that, entity framework cannot translate expressions into sql if I convert type using Convert class. like, Convert.ToDateTime(). If I do so then entity framework throws error like:
     "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. "

To rescue from  this, Microsoft introduces DbFunctions class from EF6 version. Prior of EF6 it was EntityFunctions. There are lot of built-in functions related to datetime type has been implemented there. Check them out.