What steps i should follow to use the following sql scalar value function within entity framework.
在实体框架中使用以下sql标量值函数应遵循的步骤。
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
我尝试在edmx的相同名称空间下创建一个静态类,并按如下方式定义函数
[EdmFunction("Model.Store", "GetDefaultAccount")]
public static int? GetDefaultAccount(int id, Int16 type, int assocId)
{
throw new NotSupportedException();
}
While accessing it from linq like below
从linq访问它,如下所示
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
无法转换为LINQ to Entities存储表达式,因为没有重载与传递的参数匹配
Thanks
1 个解决方案
#1
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.
不幸的是,在Entity Framework中使用标量值函数并不像预期的那么容易。经过长时间的谷歌搜索后,我发现只有两种方法可以使用标量值函数,这里最好的描述,但请记住:当您从数据库更新EDM时,对.edmx文件的所有编辑都将丢失。您每次都必须重新编辑.edmx文件。祝好运。
#1
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.
不幸的是,在Entity Framework中使用标量值函数并不像预期的那么容易。经过长时间的谷歌搜索后,我发现只有两种方法可以使用标量值函数,这里最好的描述,但请记住:当您从数据库更新EDM时,对.edmx文件的所有编辑都将丢失。您每次都必须重新编辑.edmx文件。祝好运。