如何在 Entity Framework Core 1.0 中将地理操作卸载到 SQL 服务器

How to offload geography operation to SQL Server in Entity Framework Core 1.0

如果尚不支持地理数据类型和存储过程,如何使用 Entity Framework 核心使用存储在 SQL 服务器中的地理数据?

我就是这样做的。显然你没有得到 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();
        }