none
Frage zum Entity Framework WillCascadeOnDelete RRS feed

  • Frage

  • Hallo NG,

    ich habe 2 Tabellen:

    Employee hat eine List von InformationsTypes

    InformationsTypes hat einen Key auf die Tabelle Employee

    HasRequired<Employees>(s => s.Employee)
                      .WithMany(s => s.InformationsTypesList)
                      .HasForeignKey(s => s.EmployeeRid)
                      .WillCascadeOnDelete(true);

    HasMany(e => e.InformationsTypesList)
                    .WithRequired(e => e.Employee)
                    .HasForeignKey(e => e.EmployeeRid)
                    .WillCascadeOnDelete(true);

    So wie ich es verstehe, kann ich den Employee löschen, dann wird die Abhängigkeit InformationsTypes ebenfalls gelöscht. Umgekehrt auch. Ich möchte aber das der Employee nicht gelöscht werden kann, solange noch InformationsTypes vorhanden sind. Wenn ich aber beim Employee den WillCascadeOnDelete(false) mache bekomme ich eine Fehlermeldung von EF.
    Wie kann ich das lösen?

    Danke im voraus für jeden Hinweis und Tipp.

    Grüße Ingo


    Montag, 6. Februar 2017 18:41

Antworten

Alle Antworten