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.
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.
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.
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
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.
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.
For more information click here
In case anyone comes across this old post, System.Data.Entity.EntityFunctions
is now obsolete and replaced with System.Data.Entity.DbFunctions
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With