![](/img/trans.png)
[英]Fast find if points belong to polygon (NetTopologySuite.Geometries, C#. .net core 2.2)
[英]Mapping geometries with EF Core 2.2, Npgsql and NetTopologySuite
我正在尝试映射这个类:
using NetTopologySuite.Geometries;
using System.Collections.Generic;
namespace Project.API.Models
{
public class Geo
{
public int Id { get; set; }
public IEnumerable<Geometry> Geometries{ get; set; }
}
}
但是当我尝试添加一个新的迁移时,我遇到了这个错误:
无法映射属性“Geometry.UserData”,因为它属于“object”类型,它不是受支持的原始类型或有效的实体类型...
做一些研究( https://www.npgsql.org/efcore/mapping/nts.html )我发现我需要使用:
services.AddDbContext<DataContext>(x => x.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), o => o.UseNetTopologySuite()));
代替
services.AddDbContext<DataContext>(x => x.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
但是添加o => o.UseNetTopologySuite()
我有错误:
“NpgsqlDbContextOptionsBuilder”不包含“UseNetTopologySuite”的定义
我认为这与版本问题有关,但我使用的版本与 github ( https://github.com/npgsql/efcore.pg/issues/1024 ) 上此问题中的建议完全一致。
纽格:
正如文档所说,您需要引用Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite包。 另请注意,如果您使用 EF Core 2.2,则必须使用 NetTopologySuite 1.15.x 而不是 2.0.0; 后者仅适用于 EF Core 3.0/3.1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.