我有一个应用程序(.NET Core 3.1),它可以从数据库中提取数据并使用该数据。
以前,数据库是Ms Sql Server,我能够使用NetTopologySuite处理数据库中的空间数据。
现在数据库已更改为MySQL,并且NetTopologySuite doesn't support that。
应用程序使用MySql.Data.EntityFrameworkCore连接器。
定义:
public class ExampleObjectDefinition{
public Geometry GeoLocation { get; set; }
}
配置:
public class ExampleObjectDefinitionConfiguration: IEntityTypeConfiguration<ExampleObjectDefinition>
{
public void Configure(EntityTypeBuilder<ExampleObjectDefinition> builder)
{
builder.ToTable("Example_Table");
builder.Property(_ => _.SpatialTypedLocation)
.HasColumnName("SPATIAL_LOCATION");
}
}
是否有映射类型的方法?
谢谢!
在配置中进行了附加转换。
在我看来,源是一个视图,因此无论如何都不会使用setter。
public class ExampleObjectDefinitionConfiguration: IEntityTypeConfiguration<ExampleObjectDefinition>
{
public void Configure(EntityTypeBuilder<ExampleObjectDefinition> builder)
{
builder.ToTable("Example_Table");
builder.Property(_ => _.SpatialTypedLocation)
.HasColumnName("SPATIAL_LOCATION")
.HasConversion<MySqlGeometry?>
(
v => new MySqlGeometry(v.PointOnSurface.X, v.PointOnSurface.Y),
value => value == null ? null : new Point(value.Value.XCoordinate.Value, value.Value.YCoordinate.Value)
);
}
}