I have a postgis table named cities
public class City{
public int Id { get; set; }
public string Name { get; set; }
public PostgisMultiPolygon Geometry { get; set; }
}
I want to use Entity Framework to get data. And I created an entity type configuration like this.
public class MyConvention : EntityTypeConfiguration<City>
{
public MyConvention()
{
ToTable("cities", "public");
Property(p => p.Id).HasColumnName("gid");
Property(p => p.Name).HasColumnName("name");
Property(p => p.Geometry).HasColumnName("geom");
}
}
But Geometry property throws error.
The type 'NpgsqlTypes.PostgisMultiPolygon' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration.Property(System.Linq.Expressions.Expression>)'
If I remove the convention, and set property name same as database column name.
public class City{
public int Id { get; set; }
public string Name { get; set; }
public PostgisMultiPolygon geom { get; set; }
}
throws an other error:
(6,10) : error 3004: Problem in mapping fragments starting at line 6:No mapping specified for properties City.geom in Set Cities. An Entity with Key (PK) will not round-trip when: Entity is type [PostgisEntityFramework.City]