I have written the following code in my .net project. I’ve never used the Entity Framework before, and this is the very first thing I want to do: execute a function and save the result
using System.Data.Objects;
MyEntities entities = new MyEntities
var result0 = entities.CreateQuery<string>("SELECT XXX FROM Fn_Org_GetXXX('XXXX',2012);").first();
var result1 = entities.ExecuteFunction("fn_org_getXXX", new ObjectParameter[]
{
new ObjectParameter("location","XXXX"),
new ObjectParameter("fiscalyear",2012)
});
Both lines of code throw exception indicating that the function doesn’t exist. However, when I run the aforementioned code in SQL Server Management Studio, it works fine. I am logging in to the SQL server using the same credentials.
The error for result0 says:
‘Fn_Org_GetXXX’ cannot be resolved into a valid type or function.
The error for result1 says:
The FunctionImport ‘fn_org_getXXX’ could not be found in the
container ‘MyEntities’.
What am I doing wrong?
I don’t think SQL User Defined Functions is supported in Entity Framework right now. Here is a post that you can define it in edmx schema .
There are some updates from June 2011 CTP, but I don’t think it’s released yet.