我对 Entity Developer 和模型定义的函数有疑问。之前我将函数映射为存储过程,因为 Entity Developer 不支持数据库函数。我正在使用此 topic from devart forum 中提到的解决方案。但它现在对我来说没有用处,因为我不能在 Linq
查询中使用它作为实体上更大的 select 语句的一部分。
我正在尝试添加类似 this 的功能并按照提到的方式进行操作here 。但我遇到了这个异常
Additional information: LINQ to Entities does not recognize the method 'System.Nullable
1[System.Int32] EwBlobIleWyst(System.String, System.Nullable
1[System.Int32], System.String, System.Nullable`1[System.Int32])' method, and this method cannot be translated into a store expression.
在ssdl文件中函数是这样生成的:
<Function Name="EW_BLOB_ILE_WYST" IsComposable="true" ReturnType="decimal" BuiltIn="false" Aggregate="false" NiladicFunction="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="EWID4" StoreFunctionName="EW_BLOB_ILE_WYST">
<Parameter Name="OWNER" Type="VARCHAR2" Mode="In" />
<Parameter Name="OWNER_ID" Type="decimal" Mode="In" />
<Parameter Name="RODZ_DOK_IDS" Type="VARCHAR2" Mode="In" />
<Parameter Name="LICZ_PUSTE" Type="decimal" Mode="In" />
在csdl文件中它是这样的:
<Function Name="EwBlobIleWyst" ReturnType="Collection(Int32)" ed:Guid="f544518f-1cdd-484c-92b4-73b61491dc54">
<Parameter Name="OWNER" Type="String" />
<Parameter Name="OWNER_ID" Type="Int32" />
<Parameter Name="RODZ_DOK_DS" Type="String" />
<Parameter Name="LICZ_PUSTE" Type="Int32" />
<DefiningExpression>SELECT EWID4.EW_BLOB_ILE_WYST(:OWNER, :OWNER_ID, :RODZ_DOK_IDS, :LICZ_PUSTE) FROM KDOK_WSK</DefiningExpression>
我的实现如下所示:
[EdmFunction(@"Ewid4", @"EwBlobIleWyst")]
public virtual global::System.Nullable<int> EwBlobIleWyst(string OWNER, global::System.Nullable<int> OWNER_ID, string RODZ_DOK_IDS, global::System.Nullable<int> LICZ_PUSTE)
{
throw new NotSupportedException();
}
此代码位于部分上下文类内。 我以这种方式使用它:
DokPow = ((Ewid4)context).EwBlobIleWyst("smth", 1, null, 0)
此代码段位于使用 Linq 可查询的选择范围内
最佳答案
我刚刚得到了一个解决方案。问题出在属性、实体开发人员生成的数据库命名空间以及函数和变量类型中。 我必须做这样的事情:
[DbFunction("Ewid.Database.Entities.Store", "EW_BLOB_ILE_WYST")]
public static decimal EwBlobIleWyst(string OWNER, decimal OWNER_ID, string RODZ_DOK_IDS, decimal LICZ_PUSTE)
{
throw new NotSupportedException();
}
并将类型更改为 ssdl 文件中生成的类型,csdl 文件无关紧要,并且无需在 Entity Developer 中添加函数来建模,只需将其保留在 ssdl 文件中并在 C# 中手动映射此函数即可就像魅力一样。
关于c# - Entity Framework 6 无法识别数据库模型中的映射函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701210/