views:

16

answers:

0

I'm running in to a bit of a problem where any attempt to delete just the reference to a child also deletes the child record.

My schema looks like this

Person

Organisation

OrganisationContacts : Person OrgId PersonId Role

When removing an Organisation i want to only delete the record in OrgnaisationContacts, but not touch the Person record.

My Mapping looks like this

Code:

public OrganisationMap()
        {
             Table("Organsations");
              ....
HasMany<OrganisationContact>(x => x.Contacts)
                .Table("OrganisationContacts ")
                .KeyColumn("OrgId")
                .Not.Inverse()
                .Cascade.AllDeleteOrphan();
}

public class OrganisationContactMap : SubclassMap<OrganisationContact>
    {
        public OrganisationContactMap()
        {
            Table("OrganisationContacts");

            Map(x => x.Role, "PersonRole");
            Map(x => x.IsPrimary);
        }
    }

At the moment just removing a contact from the IList either doesn't reflect in the database at all, or it issues two delete statements DELETE FROM OrganisationContact & DELETE FROM Person, or tries to set PersonId to null in the OrganisationContacts table. All of which are not desirable.

Any help would be great appreciated.