本文介绍了EF4如何调用标量UDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从实体框架调用标量UDF在SQL Server中。它显示了在存储部分的模型浏览器。
任何帮助表示赞赏。
//在EDMX文件时,它在存储模型
将显示出来;功能名称=GetPerformanceIndicator的返回类型=浮动集合=false的内置=假NiladicFunction =假IsComposable =真ParameterTypeSemantics =AllowImplicitConversion架构=DBO>
<参数名称=INVTYPE =INT模式=在/>
<参数名称=基金TYPE =INT模式=在/>
<参数名称=电流TYPE =INT模式=在/>
< /功能>
< /模式>< / EDMX:StorageModels>
//在代码我想在论坛http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/92a3214b-a662-44d5提到调用-bed3-11eae9926be6 /
VAR的查询= _context.CreateQuery<双>(IRISModel.Store.GetPerformanceIndicator(@curr,@fund,@inv),
新System.Data.Objects.ObjectParameter( INV,invfund.Investors.Investor_ID),
新System.Data.Objects.ObjectParameter(基金,invfund.Funds.Fund_ID),
新System.Data.Objects.ObjectParameter(电流invfund.Currency.Currency_ID));
VAR X2 = query.Execute(System.Data.Objects.MergeOption.NoTracking);
X = x2.FirstOrDefault(); //<< - 这总是返回零
解决方案
您是否尝试过注意使用 [EdmFunction]
属性来调用您的自定义功能提供了钩EF
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
解决方案
Have you tried this approach? Note the use of an [EdmFunction]
attribute to provide the hook to EF for calling your custom function.
这篇关于EF4如何调用标量UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!