views:

235

answers:

1

I have a hierarchy of tables 3 levels deep (QualificaionType has many QualificationGroups, which have many Qualifications) mapped like this:

// QualificationType
HasMany(x => x.QualificationGroups)
    .Inverse()
    .KeyColumns.Add("QualificationGroupId")
    .AsBag()
    .Cascade.AllDeleteOrphan()
    .Access.CamelCaseField(Prefix.Underscore);

// Qualification Group
HasMany(x => x.Qualifications)
    .Inverse()
    .KeyColumns.Add("QualificationId")
    .AsBag()
    .Cascade.AllDeleteOrphan()
    .Access.CamelCaseField(Prefix.Underscore);

When I delete a Qualification Group, it deletes all qualifications related to it. But when I try to delete a Qualification Type, it tries to delete all related Qualification Groups but not their Qualifications.

How can I get it to cascade all the way down so that if I delete a Type, it deletes all the Groups and all of their Qualifications? Do I need to loop through all the Groups first and delete them? It seems this should be able to be handled through mappings alone.

FYI, I'm using Fluent NHibernate 1.0RTM and NHibernate 2.1

A: 

I figured it out... mappings were incorrect.

They should be this:

// QualificationType
HasMany(x => x.QualificationGroups)
    .Inverse()
    .KeyColumn("QualificationTypeId")
    .AsBag()
    .Cascade.AllDeleteOrphan()
    .Access.CamelCaseField(Prefix.Underscore);

// Qualification Group
HasMany(x => x.Qualifications)
    .Inverse()
    .KeyColumn("QualificationGroupId")
    .AsBag()
    .Cascade.AllDeleteOrphan()
    .Access.CamelCaseField(Prefix.Underscore);

I had the wrong key column in each.

Chris Conway