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

.net-core .net-core-2.2 .net-core-3.1 entity-framework entity-framework-core

Question

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
1
4/7/2020 1:04:43 PM

Accepted 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");
});
1
4/7/2020 1:17:22 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow