【发布时间】:2020-04-11 16:28:28
【问题描述】:
我正在尝试映射此类:
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:
【问题讨论】:
标签: c# .net-core entity-framework-core npgsql nettopologysuite