Visual Studio 2017 PMC 添加迁移不工作,没有错误

Visual Studio 2017 PMC Add-Migrations Not Working, No Errors

我创建了我的项目并且能够添加一些迁移并使用 PMC 相应地更新数据库。

今天;但是,我似乎根本无法添加迁移。

情况如下:

PM> add-migration EventEntities
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\MyUserAccount\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
PM> 

注意,没有错误。它只是写 "User profile is avail..." 并在挂起大约 30 秒后表现得好像什么都没发生,我的迁移没有创建...

为什么添加迁移会突然停止工作?我怎样才能让某种错误消息出现?

我尝试了几种解决方案,包括:

更新:在我的Startup.cs文件中注释掉一些代码并重新运行PMC添加迁移命令后,我开始收到以下错误:

System.InvalidOperationException: The convention invocations have reached the recursion limit. This is likely an issue in EF Core, please report it.

这似乎是我的新实体在相关实体和外键方面的设置方式引起的问题。我将向后工作以查看是否可以找到具体问题。

我确定我的问题是由相关实体关系引起的。我的解决方案是像这样指定外键:

public class Event
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    [ForeignKey("EventId")]
    public virtual ICollection<EventHostAssociation> Hosts { get; set; }
}

public class EventHostAssociation
{
    public Guid EventId { get; set; }
    public string UserId { get; set; }

    public virtual Event Event { get; set; }
    public virtual ApplicationUser User { get; set; }
}

public class ApplicationUser : IdentityUser
{
    [ForeignKey("UserId")]
    public virtual ICollection<EventHostAssociation> EventHosts { get; set; }
}

最后,在我的 ApplicationDbContext.cs 文件中,我指定了我的组合键:

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<EventHostAssociation>().HasKey(c => new { c.EventId, c.UserId });
    }

这个问题已经在这里讨论过,还有:https://github.com/aspnet/EntityFrameworkCore/issues/9265

EventHostAssociation table 应该有 Event 的外键引用 您应该在 EventHostAssociation table

中添加这一行
[ForeignKey("EventAsso")
public int EventId {get;set;}
public virtual EventHostAssociation EventAsso{get;set:}