如何从EF中的数据库调用函数

时间:2011-12-05 10:14:37

标签: sql-server entity-framework entity-framework-4.1

我从我的数据库中生成一个模型。

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

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

是其原因?

1 个答案:

答案 0 :(得分:2)

您需要在某处创建stub method for your function。它应该看起来像:

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

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