I would like to map my scalar function to my .edmx but it fails. I right click on my entity framework mapping, and choose update model from database. It appears in my stored
I've encountered same problem. And here is solution I've found my self suitable enough (tested in EF5, but should also work in EF4):
There is no support of mapping scalar-value functions out of the box but you can execute them directly.
You can also edit edmx file to make edmx generate proper method for scalar-value function, but it ll be deleted if you ll synch you model with database.
Write scalar-valued function implementation yourself:
string sqlQuery = "SELECT [dbo].[CountMeals] ({0})";
Object[] parameters = { 1 };
int activityCount = db.Database.SqlQuery(sqlQuery, parameters).FirstOrDefault();
Or edit edmx and add Xml for custom maping of scalar-valued function:
SELECT [dbo].[CountActivities] (@personId)
This information was found in this blog post