Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between SqlFunctions and EntityFunctions?

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.

like image 781
Dabbas Avatar asked Mar 26 '13 12:03

Dabbas


People also ask

What is DbFunctions?

The purpose of the DbFunctions class is to convert expressions to the proper SQL syntax: Provides common language runtime (CLR) methods that expose EDM canonical functions for use in DbContext or ObjectContext LINQ to Entities queries.


4 Answers

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.

like image 57
Phil Avatar answered Sep 29 '22 10:09

Phil


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

like image 40
Wahid Bitar Avatar answered Oct 01 '22 10:10

Wahid Bitar


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

like image 39
03Usr Avatar answered Sep 27 '22 10:09

03Usr


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

like image 21
SteveB Avatar answered Sep 29 '22 10:09

SteveB