The error I am getting is common, but in the script I did not find the answers that say in my script:
Entities:
School Teacher Student
Mapping:
School: mapping.HasMany(x => x.Students).Cascade.AllDeleteOrphan(); Student: mapping.References(x => x.Teacher).Not.Nullable().Cascade.SaveUpdate(); mapping.References(x => x.School).Not.Nullable().Cascade.SaveUpdate(); Teacher: mapping.References(x => x.School).Not.Nullable().Cascade.SaveUpdate(); mapping.HasMany(x => x.Students).Cascade.All().Inverse();
Scenario: A student is associated with a School in which there are no other students or teachers. If I want to connect a student with another school, I would like to remove the orphan school.
if (oldSchool.Students.Count == 1 && oldSchool.Teachers.Count == 0) { //delete it //oldSchool.Students.Remove(student); student.School = null; _schoolRepository.Delete(oldSchool); }
What happens is that when I go to save the โstudentโ, I get the error โthe deleted object will be cascadedโ.
As always, any help is greatly appreciated.
source share