I have the follwoing ValueConverter
class:
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetTopologySuite.Geometries;
public class GeometryConverter : ValueConverter<string, Geometry>
{
public GeometryConverter(IWKTStringConverter converter)
: base(
wtkGeometry => converter.ConvertToGeometry(wtkGeometry),
geometry => geometry.ToString())
{
}
}
And this is the builder for the entity:
var geomConverter = new Geo.GeometryConverter(new Geo.WKTStringConverter());
modelBuilder.Entity<GEOCatalog>(b => {
b.ToTable("GEOCatalog").HasKey(m => m.Id);
b.Property(m => m.Geom).HasConversion(geomConverter);
});
When I now start my server, EF Core creates the tables, but the data type of the property Geom
is geography
instead of geometry
which is not correct.
Even if I do not use a ValueConverter
and create a model whose Geom
property type is of type NetTopologySuite.Geometries.Geometry
the result in SQL Server is the same.
Maybe anyone can help with that?
By default, spatial properties are mapped to geography
columns in SQL Server. To use geometry
, configure the column type in your model.
b.Property(m => m.Geom)
.HasColumnType("geometry")
or
[Column(Type = "geometry")]
public Geometry Geom { get; set; }