【问题标题】:How to offload geography operation to SQL Server in Entity Framework Core 1.0如何在 Entity Framework Core 1.0 中将地理操作卸载到 SQL Server
【发布时间】:2016-04-24 19:03:10
【问题描述】:

如果还不支持地理数据类型和存储过程,如何使用 Entity Framework Core 使用存储在 SQL Server 中的地理数据?

【问题讨论】:

  • 目前,如果您计划发布您的应用程序,您应该使用 EF6。没有最终版本的日期......
  • @Thomas 并不总是一个选项,例如,如果针对 UWP
  • 哦...抱歉 ^^ 你看到这个问题了吗github.com/aspnet/EntityFramework/issues/1100?
  • 是的,其实上一篇有这个问题的帖子是我写的

标签: sql-server geospatial spatial entity-framework-core


【解决方案1】:

我就是这样做的。显然你没有得到 DbGeography 类型的特性,但是对于简单的查询它应该足够了。

  public async Task<List<PointOfInterest>> Execute(double latitude, double longitude, int radius)
        {
            return await this.context.PointsOfInterest.FromSql(

            "DECLARE @point geography = geography::Point(@p0, @p1, 4326); " +

            "SELECT Id, DateAdded, Latitude, Longitude " +
            "FROM dbo.PointsOfInterest " +
            "WHERE @point.STDistance(Location) <= @p2",
            longitude,
             latitude,
            radius).ToListAsync();
        }

【讨论】:

  • 如何映射您的属性“位置”? Location 是您数据库中的 sys.geography 对,但是您是如何在模型/流利的 api 中声明它的?我也有类似的问题:stackoverflow.com/questions/44873740/…
  • 我想我只是将它作为字符串映射到我的模型中,然后使用 builder.Sql() 方法添加迁移以将列更改为地理类型。您对该字段执行的任何查询/命令都需要在原始 SQL 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-19
  • 1970-01-01
相关资源
最近更新 更多