i'm working with legacy code(so i'd like to change it as little as possible), and i'm having a little trouble with a many to many relationship here.
Here's what i have:
public class Feature {
List<Profile> Profiles{get;set;}
}
public class Profile{
List<FeatureProfile> Features{get;set;}
}
public class FeatureProfile {
Feature Feat {get;set;}
Profile Profile {get;set;}
}
and their mapping is like this:
mapper.Class<Feature>(m=>
m.Bag(x => x.Profiles, bagMap =>
{
bagMap.Table("FeatureProfile");
bagMap.Key(key=>key.Column("FeatureId"));
bagMap.Cascade(Cascade.All | Cascade.DeleteOrphans);
},map=>map.ManyToMany(manyToMany=>manyToMany.Column("ProfileId")))
);
mapper.Class<Profile>(m=>
m.Bag(x => x.Features, bagMap =>
{
bagMap.Key(key=>key.Column("ProfileId"));
bagMap.Inverse(true);
bagMap.Cascade(Cascade.All | Cascade.DeleteOrphans);
})
);
mapper.Class<FeatureProfile>(m=> {
m.ManyToOne(x => x.Profile, x => x.Column("ProfileId"));
m.ManyToOne(x => x.Feat, x => x.Column("FeatureId"))
});
What I need is: When I delete a Feature, it's FeatureProfile's get deleted too. Note that I think this probably worked in NHibernate 2.x