升级到 Entity Framework 核心 3 时出错:当前上下文中不存在 RelationalReferenceCollectionBuilderExtensions

Error upgrating to Entity Framework Core 3: RelationalReferenceCollectionBuilderExtensions does not exist in the current context

我正在从 Entity Framework Core 2 升级到 Entity Framework Core 3。我遇到了这个错误:

Error CS0103 The name 'RelationalReferenceCollectionBuilderExtensions' does not exist in the current context

错误在方法 OnModelCreating(ModelBuilder modelBuilder) 上,这是代码:

modelBuilder.Entity<Person>(entity =>
        {
            //some props

            RelationalReferenceCollectionBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity
                .HasOne(d => d.RuleCodeNavigation)
                .WithMany(p => p.Person)
                .HasForeignKey(d => d.RuleCode)
                .OnDelete(DeleteBehavior.ClientSetNull), "FK_Person_Rules");
        });

似乎 class RelationalReferenceCollectionBuilderExtensions 在 EF Core 3 中不存在。 知道我该如何解决这个问题吗?

不确定 RelationalReferenceCollectionBuilderExtensions 发生了什么,但建议的约束命名方法是这样

modelBuilder.Entity<Person>(entity =>
{
    //some props
    entity
        .HasOne(d => d.RuleCodeNavigation)
        .WithMany(p => p.Person)
        .HasForeignKey(d => d.RuleCode)
        .OnDelete(DeleteBehavior.ClientSetNull)
        .HasConstraintName("FK_Person_Rules");
});