What steps i should follow to use the following sql scalar value function within entity framework.
select dbo.GetDefaultAccount(5,1,48)
I tried creating a static class under the same namespace of the edmx and defining the function as following
[EdmFunction("Model.Store", "GetDefaultAccount")]
public static int? GetDefaultAccount(int id, Int16 type, int assocId)
{
throw new NotSupportedException();
}
While accessing it from linq like below
var Accountno = (from s in dbcontext.TranSetups select new { Accountno = CutomEdmxFunctions.GetDefaultAccount(5, 1, 48) })
.FirstOrDefault().Accountno;
I get the following error
cannot be translated into a LINQ to Entities store expression because no overload matches the passed arguments
Thanks
Unfortunately, working scalar-valued functions in Entity Framework is not as easy as it supposed to be. After a long googling I found only two methods to work with scalar-valued functions, best described here, but remember: all edits to the .edmx file will be lost when you update the EDM from the database. You will have to re-edit the .edmx file each time. Good luck.