我的 ASP.NET Core 8 Web API 和 EF Core 8 应用无法识别 PostGIS 扩展中的地理类型。这是我收到的错误:
System.InvalidCastException:对于 DataTypeName 为“public.geography”的字段,不支持将其读取为“NetTopologySuite.Geometries.Point”
由于扩展安装在公共模式中,我尝试将其更改search_path
为包含“公共”,但仍然不起作用。
以下是已安装的扩展
List of installed extensions
Name | Version | Schema | Description
-------------+---------+------------+------------------------------------------------------------
aws_commons | 1.2 | public | Common data types across AWS services
aws_lambda | 1.0 | public | AWS Lambda integration
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 3.4.2 | public | PostGIS geometry and geography spatial types and functions
uuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs)
这是数据类型在实体类中的映射方式:
[Column("spatiallocation", TypeName = "geography")]
public Point? SpatialLocation { get; set; }
DbContext
注册方式如下:
services.AddDbContext<GeodataDbContext>(options =>
{
options.UseNpgsql(_configuration.GetConnectionString("GeodataConnectionString"),
b => b
.UseNetTopologySuite()
);
});