C#C
C#2y ago
Rename

"Duplicate property" Entity Framework 8 Error

I've got this error popping up on OnModelCreating method:
System.InvalidOperationException: 'The property or navigation 'Rotation' cannot be added to the 'AlternativeShift' type because a property or navigation with the same name already exists on the 'AlternativeShift' type.'


this is how I'm setting up AlternativeShift there:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<AlternativeShift>(entity =>
    {
        entity.HasKey(e => e.Id)
            .HasName("PK__Alternat__3214EC068342A05F")
            .IsClustered(false);

        entity.HasIndex(e => e.Rotation, "IX_AlternativeShifts->Rotation");
        
        entity.HasIndex(e => e.Shift, "IX_AlternativeShifts->Shift");
        
        entity.HasIndex(e => new { e.Rotation, e.Shift, e.Weekday }, "UQ_RotaShiftWeekday").IsUnique();
        
        entity.Property(e => e.Id).ValueGeneratedNever();
        
        entity.HasOne(d => d.Rotation).WithMany(p => p.AlternativeShifts)
            .HasForeignKey(d => d.RotationId)
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_AlternativeShift.Rotation");
        
        entity.HasOne(d => d.Shift).WithMany(p => p.AlternativeShifts)
            .HasForeignKey(d => d.ShiftId)
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_AlternativeShift.Shift");
        
        entity.HasOne(d => d.Weekday).WithMany(p => p.AlternativeShifts)
            .HasForeignKey(d => d.WeekdayId)
            .HasConstraintName("FK__Alternati__Weekd__1352D76D");
    });
Was this page helpful?