npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.54k stars 226 forks source link

bulk insert a 2d geometry throws "Geometry has Z dimension but column does not" exception #1921

Closed jcachat closed 2 years ago

jcachat commented 3 years ago

I have just upgraded from .Net/EF 3.1 to 5.0.8. Everything seems to be working great except that my bulk inserts of geometry columns all fail with an exception saying "Geometry has Z dimension but column does not" even though my geometries are all 2d.

I found that I can make it succeed by using .ToBinary() like this.

writer.Write(geom.ToBinary())

where previously, that was not necessary:

writer.Write(geom, NpgsqlDbType.Geometry);

Is there something broken here or is that now how it must be done? I searched all over and could not find any information about a breaking change with this or with 2d vs 3d handling.

My .UseNetTopologySuite() is just the default (no options) but also tried forcing XY like this:

.UseNetTopologySuite(handleOrdinates: NetTopologySuite.Geometries.Ordinates.XY)
roji commented 3 years ago

Can you submit a minimal code sample, with database schema and the relevant .NET code? I assume from writer.Write that you're using the COPY API (so nothing to do with EF Core)?

roji commented 2 years ago

Closing as no additional details have been provided.