Search code examples
entity-framework-4

Entity Framework 4: Math.Sin()-function


is there an possibility to call the Math.Sin()-function in a Linq To Entites (Entity Framework 4) -Query?

I've read, that the current Entity Framework 4 doesn't implement this function.

Maybe there's a workaround to this solve problem?

(I don't want to invite all entries in the memory.)

Thanks and best regards


Solution

  • Several functions that (usually) have obvious SQL counterparts, like Math.Sin can't be used directly in Entity Framework queries. Presumably this is because they can't be reliably translated to different SQL implementations. A ton of MSSQL-specific functions are, however, exposed as static methods in the class System.Data.Objects.SqlClient.SqlFunctions. They throw exceptions if you call them directly, but are translated into the proper SQL if used in a LINQ query.

    See this blog post about the magic that's happening under the covers (namely the EdmFunction attribute).