如何将SQL用户定义的函数添加到实体框架?

kan*_*oid 7 linq sql-server asp.net entity-framework-4

我可以像在.dbml中一样在我的.edmx文件中添加SQL函数吗?如果可以的话,怎么做?如果我不能,是否有任何解决方法?

我试图谷歌,但没有找到任何具体的答案,如何做到这一点.

基于给定的答案,我创建了一个存储过程,并尝试添加"导入函数",但它表示"存储过程不返回任何列".我哪里做错了?功能:

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)
)
Run Code Online (Sandbox Code Playgroud)

存储过程:

ALTER PROCEDURE USP_locationSearch
(@keyword varchar(10))
AS
BEGIN
SELECT * from dbo.fn_locationSearch(@keyword)
END
Run Code Online (Sandbox Code Playgroud)

kei*_*en7 9

实体框架中没有内置的SQL用户定义函数支持,最好的方法是创建一个包装函数调用并返回其输出的存储过程,然后将该过程添加到EF模型中.