Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用用户定义的数据库函数_C#_Linq_Entity Framework_Ef Code First_Entity Framework 6 - Fatal编程技术网

C# 调用用户定义的数据库函数

C# 调用用户定义的数据库函数,c#,linq,entity-framework,ef-code-first,entity-framework-6,C#,Linq,Entity Framework,Ef Code First,Entity Framework 6,这可能吗?我的意思是,我基本上希望做以下事情 我已经在我的数据库中创建了一个名为GetPlayerPosition的函数(尽管如果有一种方法可以使用代码优先迁移来创建它,我也可以这么做),它接受1个参数(一个表示播放器ID的整数) 我希望在我的MVC代码中使用LINQ做类似的事情: from p in db.Players select new { p.PlayerId, GetPlayerPosition(p.PlayerId)}; 我知道我不能简单地做到这一点,不幸的是(至少不能没有让EF

这可能吗?我的意思是,我基本上希望做以下事情

我已经在我的数据库中创建了一个名为GetPlayerPosition的函数(尽管如果有一种方法可以使用代码优先迁移来创建它,我也可以这么做),它接受1个参数(一个表示播放器ID的整数)

我希望在我的MVC代码中使用LINQ做类似的事情:

from p in db.Players
select new { p.PlayerId, GetPlayerPosition(p.PlayerId)};

我知道我不能简单地做到这一点,不幸的是(至少不能没有让EF认识到这个功能的方法),但我已经尝试了一段时间寻找一种方法来做到这一点,我只是在旋转我的轮子。感谢您的帮助

您可以先使用调用代码中的存储过程、TVF和标量UDF(EF 6.1.1)。

我会看一下,非常感谢您提供的信息,Pawel!不幸的是,由于我是一个新用户,我无法投票支持。