实体框架核心-EF核心2.2-'Point.Boundary'是接口类型('IGeometry')

Les*_*s P 7 entity-framework-core-2.1 asp.net-core-2.2

我正在尝试EF Core 2.2的新功能。它基于以下文章。“宣布实体框架核心2.2” https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-entity-framework-core-2-2/

我安装了以下Nuget软件包。

在此处输入图片说明

我在模型中添加了以下内容。

using NetTopologySuite.Geometries;


//New as of EF.Core 2.2 
//[Required] 
//[NotMapped] 
public Point Location { get; set; }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

在应用程序启动期间,在以下行中的数据库上下文中出现以下错误:Database.EnsureCreated();

在此处输入图片说明

System.InvalidOperationException HResult = 0x80131509 Message =属性“ Point.Boundary”具有接口类型(“ IGeometry”)。如果它是导航属性,则通过将其强制转换为映射的实体类型来手动配置此属性的关系,否则使用“ OnModelCreating”中的NotMappedAttribute或“ EntityTypeBuilder.Ignore”忽略该属性。源= Microsoft.EntityFrameworkCore

Kyl*_*yle 14

您需要致电UseNetTopologySuite()。这里的例子:

public class ApplicationDbContext : IdentityDbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {

    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        IConfigurationRoot configuration = new ConfigurationBuilder()
           .SetBasePath(Directory.GetCurrentDirectory())
           .AddJsonFile("appsettings.json")
           .Build();
        var connectionString = configuration.GetConnectionString("DefaultConnection");
        optionsBuilder.UseSqlServer(connectionString, opts => opts.UseNetTopologySuite());
    }
    public DbSet<Test> Tests { get; set; }
}


public class Test
{
    public int Id { get; set; }
    public Point Location { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我遇到这个问题是因为我的 if (!optionsBuilder.IsConfigured)周围都有东西OnConfiguring。我必须删除它才能开始add-migrations工作。