实体框架核心-EF核心2.2-'Point.Boundary'是接口类型('IGeometry') [英] Entity Framework Core - EF Core 2.2 - 'Point.Boundary' is of an interface type ('IGeometry')

查看:135
本文介绍了实体框架核心-EF核心2.2-'Point.Boundary'是接口类型('IGeometry')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying the new functionality with EF Core 2.2. It is based on the following article. "Announcing Entity Framework Core 2.2" https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-entity-framework-core-2-2/

我安装了以下Nuget软件包.

I installed the following Nuget package.

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

I added the following to my model.

using NetTopologySuite.Geometries;


//New as of EF.Core 2.2 
//[Required] 
//[NotMapped] 
public Point Location { get; set; }

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

During my application startup I get the following error in my Database Context on the following line: Database.EnsureCreated();

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

System.InvalidOperationException HResult=0x80131509 Message=The property 'Point.Boundary' is of an interface type ('IGeometry'). If it is a navigation property manually configure the relationship for this property by casting it to a mapped entity type, otherwise ignore the property using the NotMappedAttribute or 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. Source=Microsoft.EntityFrameworkCore

推荐答案

您需要致电UseNetTopologySuite().此处的示例:

You need to call UseNetTopologySuite(). Example here:

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; }
}

我遇到了这个问题,因为我有一个 if (!optionsBuilder.IsConfigured)围绕我OnConfiguring中的所有内容.为了使add-migrations正常工作,我必须删除它.

I ran into this problem because I had a if (!optionsBuilder.IsConfigured) around everything in my OnConfiguring. I had to remove this in order to get add-migrations to work.

这篇关于实体框架核心-EF核心2.2-'Point.Boundary'是接口类型('IGeometry')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆