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

307 Views Asked by At

Im upgrating from Entity Framework Core 2 to Entity Framework Core 3. And I have this error:

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

The error is on method OnModelCreating(ModelBuilder modelBuilder), this is the code:

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

It seems the class RelationalReferenceCollectionBuilderExtensions does not exist in EF Core 3. Any idea how I can fix this?

1

There are 1 best solutions below

0
On BEST ANSWER

Not sure what happened to RelationalReferenceCollectionBuilderExtensions, but the suggested method to name your constraints is this

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