0

我正在尝试映射此类:

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”,因为它属于“对象”类型,不是受支持的原始类型或有效的实体类型...

做一些研究(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)上的这个问题中的建议完全相同。

NuGet:

在此处输入图像描述

4

1 回答 1

2

正如文档所说,您需要引用Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite包。另请注意,如果您使用 EF Core 2.2,则必须使用 NetTopologySuite 1.15.x 而不是 2.0.0;后者仅适用于 EF Core 3.0/3.1。

于 2019-12-19T13:07:54.240 回答