What is the equivalent of DbGeography in EF core?
Asked Answered
V

2

5

What is the equivalent of DbGeography in EF core?
I want to convert the following code from EF to EF Core:

using System.Data.Entity.Spatial;

namespace Domain
{
    public class City
    {
        public int CityId { get; set; }
        
        public DbGeography Coordinates { get; set; }
    }
}
Vortical answered 10/7, 2021 at 7:6 Comment(0)
O
8

You have to use NetTopologySuite with EF Core and there is list of libraries which enables that for specific Data Provider: https://learn.microsoft.com/en-us/ef/core/modeling/spatial

Onia answered 10/7, 2021 at 9:16 Comment(0)
V
4

In order to use spatial data with EF Core, we need to install the appropriate supporting NuGet package.
For example Spatial NuGet Package of Microsoft.EntityFrameworkCore.SqlServer is Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
Then we can use this spatial types:

  • Geometry
  • Point
  • LineString
  • Polygon
  • GeometryCollection
  • MultiPoint
  • MultiLineString
  • MultiPolygon

By default, spatial properties are mapped to geography columns in SQL Server.
To use geometry, we configure the column type in our model.

Vortical answered 10/7, 2021 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.