How to set the "cascade delete" parameter to "Set Null" in Fluent NHibernate?

I am new to Fluent nHibernate and would like to know if I have two Profile and Email classes, one-to-many mappings, as shown below ... I want to clearly define the nHibernate mapping so that when deleting the profile they remain in the database with the key set to null. Or, in other words, have "ON DELETE SET NULL"

ALTER TABLE [dbo].[Email]  WITH CHECK ADD  CONSTRAINT [FK4239B252F6539048] FOREIGN KEY([ProfileId])
REFERENCES [dbo].[Profile] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL

Any help is much appreciated!

public sealed class ProfileMapping : ClassMap<Profile>
        {
            public ProfileMapping()
            { 
                // Some other fields here ...
                HasMany(x => x.Emails);
            }
        }

    public class EmailMapping : ClassMap<Email>
    {
        public EmailMapping()
        {
            Id(x => x.Id).GeneratedBy.GuidComb();
            Map(x => x.Address).Not.Nullable().UniqueKey("UX_EmailAddress").Length(254);
            Map(x => x.Confirmed);
        }
    }
+5
source share
1 answer

Fluent NHibernate AFAIK. ON DELETE/ON UPDATE , NHibernate, NH/FNH :

none - do not do any cascades, let the users handles them by themselves.
save-update - when the object is saved/updated, check the assoications and save/update any object that require it (including save/update the assoications in many-to-many scenario).
delete - when the object is deleted, delete all the objects in the assoication.
delete-orphan - when the object is deleted, delete all the objects in the assoication. In addition to that, when an object is removed from the assoication and not assoicated with another object (orphaned), also delete it.
all - when an object is save/update/delete, check the assoications and save/update/delete all the objects found.
all-delete-orphan - when an object is save/update/delete, check the assoications and save/update/delete all the objects found. In additional to that, when an object is removed from the assoication and not assoicated with another object (orphaned), also delete it.

, "SET NULL" .

, , - , "" (E-mails "", ; "" E- ), , NHibernate, , "" .

+7

All Articles