11

I recently upgraded to the newest version of EntityFrameworkCore.PostgreSQL but the spacial data didn't seem to work, because they now use NetTopologySuite see here

To set up the NetTopologySuite plugin, add the Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite nuget to your project. Then, make the following modification to your UseNpgsql() line:

I use the dotnet ef dbcontext scaffold command

dotnet ef dbcontext scaffold "MyConnectionString" Npgsql.EntityFrameworkCore.PostgreSQL

however, the scaffold command doesn't seem to use the NetTopologySuite mapping. I still get the following error

Could not find type mapping for column 'public.behaviour.coord' with data type 'geometry(Point)'. Skipping column.

How can I scaffold my database using NetTopologySuite

Pepernoot
  • 3,409
  • 3
  • 21
  • 46
  • Maybe that post can help you? https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/441 – Legion Jul 11 '18 at 15:02

3 Answers3

0

I had a similar problem, after updating the postgre library, I had to delete migration files and regenerate new ones

siasty
  • 167
  • 1
  • 2
  • 10
0
public class EFDesignTimeService : IDesignTimeServices
{
    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
        new EntityFrameworkRelationalServicesBuilder(services).TryAddProviderSpecificServices(x =>
        {
            x.TryAddSingleton<INpgsqlOptions, NpgsqlOptions>(p =>
            {
                var dbOption = new DbContextOptionsBuilder()
                    .UseNpgsql("connection string",
                        ob => ob.UseNodaTime().UseNetTopologySuite()).Options;
                var npgOptions = new NpgsqlOptions();
                npgOptions.Initialize(dbOption);
                return npgOptions;
            });
        });
    }
}
grabhints
  • 680
  • 8
  • 23
0

I was using the geometry(Point, 4326) type and I had to change the type to geometry

ALTER COLUMN coord TYPE geometry;
Pepernoot
  • 3,409
  • 3
  • 21
  • 46