If you want to call an SQL function, you must execute your own SQL query. To do this, use context.Database.SqlQuery. Entity structure supports stored procedure mapping, but this function is not supported in the DbContext API (EF 4.1). If you want to call a stored procedure, you must use context.Database.SqlQuery again. Stored procedures can never be used in Linq queries.
EdmFunction is an ObjectContext API function and an Entity constructor. The namespace is set to the namespace defined in the EDMX file. When using the code, you do not have the EDMX file at first, and you cannot determine the mapping of functions.
Btw. if you follow the first approach of the code, you should not have any stored procedures or SQL functions, because your database is defined by your model (code) and generated by the entity framework.
Ladislav Mrnka
source share