EF4如何调用标量UDF

时间:2011-05-11 18:04:13

标签: c# entity-framework entity-framework-4

我试图从实体框架中调用SQL Server中的标量UDF。它显示在Store部分的模型浏览器中。

任何帮助都是赞赏的。

 //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 个答案:

答案 0 :(得分:4)

您是否尝试过this approach?请注意使用[EdmFunction]属性为EF提供挂钩以调用自定义函数。