【发布时间】:2014-02-21 22:58:14
【问题描述】:
我试过这个:
GetProvinceCodeByLatLong(a.Latitude, a.Longitude)
我这样声明函数:
[DbFunction("Core.Models", "fn_GetProvinceCodeByLatLong")]
public static string GetProvinceCodeByLatLong(double latitude, double longitude)
{
throw new NotSupportedException("Direct calls are not supported.");
}
在 edmx 文件中我有这个:
<Function Name="fn_GetProvinceCodeByLatLong" ReturnType="varchar" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
<Parameter Name="latitude" Type="float" Mode="In" />
<Parameter Name="longitude" Type="float" Mode="In" />
</Function>
但是Entity Framework抛出无法构造查询的异常。
我收到此错误:
“Infrastructure.CustomRepositories.AssetDataRepository”类型上的指定方法“System.String GetProvinceCodeByLatLong(Double, Double)”无法转换为 LINQ to Entities 存储表达式
【问题讨论】:
-
EdmFunction 我认为是过时的功能,而不是它,我们需要在最新的 EF 中使用 DBFunction
标签: c# linq entity-framework tsql