Fluent NHibernate - Set reference key columns to null

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-04-20T14:14:15Z Indexed on 2010/05/20 20:20 UTC
Read the original article Hit count: 194

Hi,

I have a table of Appointments and a table of AppointmentOutcomes. On my Appointments table I have an OutcomeID field which has a foreign key to AppointmentOutcomes. My Fluent NHibernate mappings look as follows;

        Table("Appointments");
        Not.LazyLoad();
        Id(c => c.ID).GeneratedBy.Assigned();
        Map(c => c.Subject);
        Map(c => c.StartTime);
        References(c => c.Outcome, "OutcomeID");


        Table("AppointmentOutcomes");
        Not.LazyLoad();
        Id(c => c.ID).GeneratedBy.Assigned();
        Map(c => c.Description);

Using NHibernate, if I delete an AppointmentOutcome an exception is thrown because the foreign key is invalid. What I would like to happen is that deleting an AppointmentOutcome would automatically set the OutcomeID of any Appointments that reference the AppointmentOutcome to NULL.

Is this possible using Fluent NHibernate?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about fluent-nhibernate