dotnet core database first using NetTopologySuite
Asked Answered
S

3

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

Suppliant answered 21/6, 2018 at 13:25 Comment(1)
Maybe that post can help you? github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/…Hardware
Q
0

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

Quickwitted answered 4/9, 2018 at 6:35 Comment(0)
H
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;
            });
        });
    }
}
Heartsease answered 25/2, 2019 at 18:22 Comment(0)
S
0

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

ALTER COLUMN coord TYPE geometry;
Suppliant answered 26/2, 2019 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.