c# - EF Core Cascade Delete error with Oracle DB First

Viewed 62

I have an implicit Many to Many relation and I have setup the modelBuilder as such

modelBuilder.Entity<Materia>().HasMany(p => p.PROFESSORT_).WithMany(p => p.MATERIAT_)
            .UsingEntity<Dictionary<string, object>>(
            "MATERIATPROFESSORT",
            j => j
                .HasOne<Professor>()
                .WithMany()
                .HasForeignKey("PROFESSORT_IDPROFESSOR")
                .HasConstraintName("MATERIATPPROFESSORT_PROFESSORT_FK")
                .OnDelete(DeleteBehavior.Cascade),
            j => j
                .HasOne<Materia>()
                .WithMany()
                .HasForeignKey("MATERIAT_IDMATERIA")
                .HasConstraintName("MATERIATPROFESSORT_MATERIAT_FK")
                .OnDelete(DeleteBehavior.Cascade));

however I keep getting an integrity violation error

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.

 ---> Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-02292: restrição de integridade (RM87329.MATERIATPROFESSORT_MATERIAT_FK) violada - registro filho localizado
ORA-06512

So it's violating the foreign key integrity, but shouldn't the .OnDelete(DeleteBehavior.Cascade) deal with this appropriately?

0 Answers
Related