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

entity-framework-core geospatial spatial sql-server

Question

How to consume geography data stored in SQL Server using Entity Framework Core if geography data type is not yet supported and stored procedures too?

1
2
4/24/2016 7:03:10 PM

Accepted Answer

This is how i've done it. Obviously you don't get the features of the DbGeography type, but for simple queries it should suffice.

  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();
        }
1
11/29/2016 11:41:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow