我可以像在 .dbml 中那样向 .edmx 文件添加 SQL 函数吗?如果可以的话,我该怎么做?如果不能,有什么解决方法吗?
我尝试在 Google 上搜索,但找不到任何有关如何执行此操作的具体答案。
根据给定的答案,我创建了一个存储过程并尝试添加“导入函数”,但它显示“存储过程不返回列”。我哪里做错了? 功能:
ALTER FUNCTION [dbo].[fn_locationSearch](@keyword varchar(10))
RETURNS TABLE
AS
RETURN
(
SELECT CustomerBranch.ID,CustomerBranch.BranchName,CustomerBranch.Longitude,CustomerBranch.Latitue,CustomerBranch.Telephone,CustomerBranch.CategoryID,CustomerBranch.Description
FROM FREETEXTTABLE (CustomerOffer,*,@keyword) abc INNER JOIN OffersInBranch
ON abc.[key]=OffersInBranch.OfferID INNER JOIN CustomerBranch ON OffersInBranch.BranchID=CustomerBranch.ID
UNION
SELECT CustomerBranch.ID,CustomerBranch.BranchName,CustomerBranch.Longitude,CustomerBranch.Latitude,CustomerBranch.Telephone,CustomerBranch.CategoryID,CustomerBranch.Description
FROM CustomerBranch WHERE FREETEXT(*,@keyword)
)
存储过程:
ALTER PROCEDURE USP_locationSearch
(@keyword varchar(10))
AS
BEGIN
SELECT * from dbo.fn_locationSearch(@keyword)
END
最佳答案
Entity Framework 中没有对 SQL 用户定义函数的内置支持,最好的方法是创建一个存储过程来包装函数调用并返回其输出,然后将该过程添加到您的 EF 模型中。
关于asp.net - 如何将SQL用户自定义函数添加到 Entity Framework 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8051299/