XperiAndri
XperiAndri

Reputation: 1208

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

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?

Upvotes: 2

Views: 782

Answers (1)

MrBliz
MrBliz

Reputation: 5898

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();
        }

Upvotes: 1

Related Questions