Nhibernate from many to many deletions

I have 2 classes that have many different relationships. I would like that every time I delete one side ONLY, association records will be deleted without any side that I will delete.

simplified model:

classes:

class Qualification
{
     IList<ProfessionalListing> ProfessionalListings 
}

class ProfessionalListing
{
     IList<Qualification> Qualifications

     void AddQualification(Qualification qualification)
     {
        Qualifications.Add(qualification);
        qualification.ProfessionalListings.Add(this);
     } 
}

free autopilot with overrides:

void Override(AutoMapping<Qualification> mapping)
{
     mapping.HasManyToMany(x => x.ProfessionalListings).Inverse();
}

void Override(AutoMapping<ProfessionalListing> mapping)
{
    mapping.HasManyToMany(x => x.Qualifications).Not.LazyLoad();
}

I try to use various combinations of cascading and inverse settings, but I can never get there. If I do not have cascades and there are no reverse, I get duplicate objects in my collections. Setting the inverse on one side makes the duplication go away, but when I try to delete the qualification, I get that "the deleted object will be re-cascaded."

How should I do it?

Should I be responsible for clearing the associations of every object that I delete?

+3
2

" " (ProfessionalListings Qualifications). , , ?

NHibernate, . , , , . NHibernate ( ) .

ProfessionalListings - , , , . , , Qualifications, . , -.

+2

, AllDeleteOrphan. , ,

0

Source: https://habr.com/ru/post/1743339/


All Articles