标量值函数的实体框架Edmx函数

时间:2014-01-20 08:05:36

标签: entity-framework user-defined-functions sql-function

我已阅读并尝试了this link中描述的所有内容以使此代码运行但我失败了。它说“无法转换为LINQ to Entities存储表达式。”

MyDb是我的MsSql数据库

GetDistance是我的标量值函数返回十进制

MyDbEntities as entity

MyDbModel as e.f. db模型

这是我的edmx文件

<Function Name="GetDistance" ReturnType="decimal" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
          <Parameter Name="lat1" Type="decimal" Mode="In" />
          <Parameter Name="lon1" Type="decimal" Mode="In" />
          <Parameter Name="lat2" Type="decimal" Mode="In" />
          <Parameter Name="lon2" Type="decimal" Mode="In" />
        </Function>

这是我的Edm函数(MyDbEntites的部分类)

[EdmFunction("MyDbModel.Store", "GetDistance")]
public static decimal GetDistance(decimal lat1, decimal lon1, decimal lat2, decimal lon2)
{
    throw new NotSupportedException("Direct calls not supported");
}

这是我的查询

var query = (from city in context.TableCity
                             where
                                 city.IsActive
                             select new
                                 {                                         
                                     Distance = MyDbEntities.GetDistance(0, 0, city.Latitude, city.Longitude)
                                 });

谢谢

0 个答案:

没有答案
相关问题