EF4 how to call a scalar UDF

主宰稳场 提交于 2019-12-10 10:30:15

问题


I am trying to call a scalar UDF in SQL Server from the entity framework. It shows up in the the model browser in the Store section.

Any help is Appreciated..

 //In the EDMX File it shows up in the storage model

<Function Name="GetPerformanceIndicator" ReturnType="float" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
          <Parameter Name="inv" Type="int" Mode="In" />
          <Parameter Name="fund" Type="int" Mode="In" />
          <Parameter Name="curr" Type="int" Mode="In" />
        </Function>
      </Schema></edmx:StorageModels>

// In the Code I am trying to call as mentioned in the Forum http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/92a3214b-a662-44d5-bed3-11eae9926be6/
var query = _context.CreateQuery<double>("IRISModel.Store.GetPerformanceIndicator(@curr, @fund, @inv)",
                        new System.Data.Objects.ObjectParameter("inv", invfund.Investors.Investor_ID),
                        new System.Data.Objects.ObjectParameter("fund", invfund.Funds.Fund_ID),
                       new System.Data.Objects.ObjectParameter("curr", invfund.Currency.Currency_ID));

                    var x2 = query.Execute(System.Data.Objects.MergeOption.NoTracking);

                    x = x2.FirstOrDefault(); //<<-- This always return zero

回答1:


Have you tried this approach? Note the use of an [EdmFunction] attribute to provide the hook to EF for calling your custom function.



来源:https://stackoverflow.com/questions/5968592/ef4-how-to-call-a-scalar-udf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!