无法生成存储函数的函数导入返回类型

Yan*_*n D 5 entity-framework stored-functions

我在我的 SQLEXPRESS(通过 Visual Studio 生成)中保存了以下简单的标量函数,并通过 VS 运行它作为 SQLQuery1.sql 工作得很好。

CREATE FUNCTION [dbo].[AveragePurchase]
(
@CustomerID int
)
RETURNS DECIMAL(8,3)
AS
BEGIN
DECLARE @Average DECIMAL(8,3)
SELECT @Average = avg(PurchaseAmount)
FROM Purchases1
WHERE CustomersCustomerID = @CustomerID;
RETURN @Average
END
Run Code Online (Sandbox Code Playgroud)

我他们去更新数据库中的模型并运行向导检查了该功能以告诉 VS 将其合并到模型中。我似乎遇到了以下警告:

Warning 1 Error 6046: Unable to generate function import return type of the store function 'AveragePurchase'. The store function will be ignored and the function import will not be generated.

我一定忽略了一些很明显的东西,但似乎无法找到如何纠正它所抱怨的问题。任何帮助表示赞赏。谢谢!

Mat*_*pen 6

遇到同样的问题并从微软找到了这个答案。

不幸的是,对于标量 UDF,即使在 Entity Framework 6 或 6.1 中默认也不支持它。在 Entity Framework 中使用它的一种方法是使用标量 UDF 创建存储过程并在项目中调用该存储过程。

来源:微软msdn