如何从EF中的数据库调用函数 [英] How call functions from data base in EF

查看:319
本文介绍了如何从EF中的数据库调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在.edmx文件中,我有一个行字符串

 < Function Name =GetUniqueIntReturnType =intAggregate =falseBuiltIn =falseNiladicFunction =falseIsComposable =trueParameterTypeSemantics =AllowImplicitConversion dbo/> 

为其原因?

解决方案

您需要为您的功能创建存根方法某处它应该看起来像:

  [EdmFunction(YourModelNamespace,GetUniqueInt)] 
public static int GetUniqueInt )
{
抛出新的NotSupportedException(不支持直接调用);
}

将此方法放在您的上下文类中,并在LINQ查询中使用它。


I generate a model from my database.

In the .edmx file I have a row string

<Function Name="GetUniqueInt" ReturnType="int" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" />

as its cause?

解决方案

You need to create stub method for your function somewhere. It should look like:

[EdmFunction("YourModelNamespace", "GetUniqueInt")]
public static int GetUniqueInt()
{
    throw new NotSupportedException("Direct calls are not supported.");
}

Place this method for example to your context class and use it in LINQ queries.

这篇关于如何从EF中的数据库调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆