4

我正在尝试将点类型保存到 Postgresql 中,我已经尝试过这种方式。(数据库表模型定义)

 public NpgsqlPoint Position { get; set; }

我用这个方法设置对象

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

但是当我在 dbContext 上调用 .SaveChanges 时,我得到了 Not Null Constraint Violation 的异常,所以我猜 EF 正试图插入一个空值。

我在进入之前调试了 posData.Position 并且对象包含正确的数据。

我已经搜索了谷歌,但我没有找到任何示例或遇到相同问题的人。

任何线索?

4

2 回答 2

1

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.

于 2013-07-15T13:36:56.897 回答
1

它看起来像是NpgsqlPoint一个PostgreSQLpoint类型。这PostGIS Extension 使用的POINTgeometry类型geometry(Point, 4326)不同(例如, )。

要制作 PostGIS geometry,您将需要x,ysrid(空间参考 ID;例如参见http://spatialreference.org/)。这些可以与ST_MakePoint几何构造函数和ST_SetSRID一起使用以建立空间参考。例如,这是一个参数化命令:

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

假设 WGS84 坐标 (SRID=4326)。

于 2013-07-15T02:17:27.870 回答