Cannot insert Geometry
Posted: Mon 03 Nov 2014 11:13
I'm having problems inserting geometries into a Postgres/Postgis database table. The prepare statement fails with the Exception "Cannot convert value".
I've created a small demo project. All I want to do is following:
In C# I've done this:
The first insert succeeds but the second one throws an exception at the last statement (SaveChanges). I'm tested it in VS2013 with EF6 (and 5) and dotConnect for Postgres 7.3.264 on Postgres 9.3 (and 9.1) with PostGIS 2.1 (and 2.0).
The exception is of type "System.Data.Entity.Core.UpdateException" with the inner exception "System.ArgumentException" and the message "Cannot convert value".
I've compiled some resources for easy reproduction under following dropbox link:
https://dl.dropboxusercontent.com/u/486 ... eption.zip
This download includes the error log from dbMonitor, the exception details, a demo solution for Visual Studio 2013 and the ddl script for the PostGIS enabled Postgres database.
Many thanks,
Christoph
I've created a small demo project. All I want to do is following:
Code: Select all
INSERT INTO public.geomtest(description, the_geom)
VALUES ('Insert test', st_geomfromtext('POINT(10 20)', 4326))
RETURNING id
Code: Select all
using (var con = new DevartTestEntities())
{
var desctest = new Geomtest();
desctest.Description = "Inserted 1 item without geometry";
con.Geomtests.AddObject(desctest);
con.SaveChanges();
var geomtest = new Geomtest();
geomtest.Description = "Inserted 1 item with geometry";
geomtest.TheGeom = DbGeometry.PointFromText("POINT(10 20)", 4326);
con.Geomtests.AddObject(geomtest);
con.SaveChanges();
}
The first insert succeeds but the second one throws an exception at the last statement (SaveChanges). I'm tested it in VS2013 with EF6 (and 5) and dotConnect for Postgres 7.3.264 on Postgres 9.3 (and 9.1) with PostGIS 2.1 (and 2.0).
The exception is of type "System.Data.Entity.Core.UpdateException" with the inner exception "System.ArgumentException" and the message "Cannot convert value".
I've compiled some resources for easy reproduction under following dropbox link:
https://dl.dropboxusercontent.com/u/486 ... eption.zip
This download includes the error log from dbMonitor, the exception details, a demo solution for Visual Studio 2013 and the ddl script for the PostGIS enabled Postgres database.
Many thanks,
Christoph