سؤال

I am trying to save a Point Type into Postgresql I have tried this way. (Db table Model definition)

 public NpgsqlPoint Position { get; set; }

I set the Object with this method

  posData.Position = new NpgsqlPoint (34.3244,23.2344);

But when i call .SaveChanges on the dbContext i get an exception of Not Null Constraint Violation , so i guess EF is trying to insert a null.

I have debuged the posData.Position before entry and the object contains proper data.

I have searched google but i didn't find any example or someone having the same problem.

Any Clues?

هل كانت مفيدة؟

المحلول 2

Update :

Full Native PostGIS for Npgsql is shceduled to be released with version 3.1. Quote from npgsql.org version 3 release notes.

Major goals for Npgsql 3.1 includes: Full, native PostGIS support (#529)

And for those who want to keep up with the changes. Here is the feature branch conversation. Support for 2D PostGIS is already merged to default.

For Npgsql version 2.x here is my old answer.

I Posted the question in Npgsql Development forum , and got my answer.

NpgSqlPoint type is not yet Supported by EF due to Entity Framework Data type Restriction.

Seems they are still working on this one.

نصائح أخرى

It looks like NpgsqlPoint makes a PostgreSQL point type. This is not the same as a POINT geometry type used by the PostGIS Extension (e.g., geometry(Point, 4326)).

To make a PostGIS geometry, you will need x, y and srid (spatial reference ID; e.g. see http://spatialreference.org/). These can be used with a ST_MakePoint geometry constructor, and ST_SetSRID to establish the spatial reference. For example, here's a parameterized command:

SELECT ST_SetSRID(ST_MakePoint(:long:, :lat:), 4326)

which assumes a WGS84 coordinate (SRID=4326).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top