簡體   English   中英

EF4如何調用標量UDF

[英]EF4 how to call a scalar UDF

我試圖從實體框架在SQL Server中調用標量UDF。 它顯示在“商店”部分的模型瀏覽器中。

任何幫助表示贊賞。

 //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

您是否嘗試過這種方法? 請注意,使用[EdmFunction]屬性可提供EF的掛鈎,以調用您的自定義函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM