How to call Scalar-valued function from LINQ to Entities server-side

前端 未结 2 459
无人及你
无人及你 2020-12-31 17:36

I have a Scalar-valued function in my DB:

ALTER FUNCTION [dbo].[fx_fooFunct]
  (@MyParam varchar(max))
RETURNS varchar(max)
AS
BEGIN
  return @MyParam
END
         


        
2条回答
  •  悲&欢浪女
    2020-12-31 18:19

    Do you have your function mapped in EDMX? I guess you don't.

    Run Update from database wizard in the designer and under stored procedures select your SQL function to import and follow this article to create helper method marked with EdmFunctionAttribute to expose the SQL function for LINQ-TO-Entities.

    Note: SQL functions are not supported in code-first / fluent-API. You need to use mapping with EDMX.

    ExecuteFunction is used to call features mapped in EDMX - it expects name of the mapped feature (function imports of stored procedures). MSDN says that it can also call mapped functions but I don't know how - it calls function import and SQL function import doesn't have any.

提交回复
热议问题