19

What's the difference ? Are both used to perform functions in sql side before get data and store them in memory ?

P.S:
Both used in linq to entites.

Dabbas
  • 3,112
  • 7
  • 42
  • 75

4 Answers4

17

As the documentation states EntityFunctions

Provides common language runtime (CLR) methods that expose conceptual model canonical functions in LINQ to Entities queries. For information about canonical functions, see Canonical Functions (Entity SQL).

where Canonical functions

are supported by all data providers, and can be used by all querying technologies. Canonical functions cannot be extended by a provider. These canonical functions will be translated to the corresponding data source functionality for the provider. This allows for function invocations expressed in a common form across data sources.

Whereas SQLFunctions

Provides common language runtime (CLR) methods that call functions in the database in LINQ to Entities queries.

Therefore although both sets of functions are translated into native SQL, SQLFunctions are SQL Server specific, whereas EntityFunctions aren't.

Phil
  • 42,255
  • 9
  • 100
  • 100
  • What I understood from your answer is that both executed in sql (in case I'm using it). Right ? – Dabbas Mar 26 '13 at 12:55
  • well, I don't belive this is true. I just had to change all my `SqlFunctions.DateDiff` to `DbContext.DiffDays` because the later `cannot be translated`.... and using SqlServer 2012 local db... – Leonardo Aug 20 '15 at 17:37
5

As i read about it. The CLR convert EntityFunctions functions to "canonical functions" which are supported by all data providers.

But the SqlFunctions make the SQL Server to do the work and they specified just for SQL Server.

For more information

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
5

SqlFunctions is a static class introduced in EF4 and is in assembly System.Data.Entity. It contains a long list of methods like Cos, DateAdd, DateDiff, DatePart, GetDate, Exp, Sign, which are mapped to SQL Server functions. These static functions can be called in LINQ to Entities queries.

enter image description here

EF4 also introduced the static EntityFunctions class. This class exposes conceptual model canonical functions which can be used in LINQ to Entities queries. These functions are mapped to the functions in the System.Data.Metadata.Edm namespace and they are only available in the conceptual model.

enter image description here

For more information click here

03Usr
  • 3,335
  • 6
  • 37
  • 63
4

In case anyone comes across this old post, System.Data.Entity.EntityFunctions is now obsolete and replaced with System.Data.Entity.DbFunctions.

SteveB
  • 233
  • 3
  • 12