Search code examples
c#fluent-nhibernatenhibernate-mapping

fluent nhibernate subclass on delete cascade


First of all, I'm quite a newbie in FluentNHibernate.

I have these DB tables, modelling a class and its subclass :

Table MyClass :
id (PK)
...

Table MySubClass :
id (PK) (FK references Class(id) on delete cascade)
...

I would like to map this in FluentNHibernate so it can regenerate the DB model, including the "on delete cascade", but I can't find how.

I have this mapping :

public class MyClassMap : ClassMap<MyClass>
{
    public MyClassMap()
    {
        this.Id(x => x.Id, "id");
        // snip
    }
}

public class MySubClassMap : SubclassMap<MySubClass>
{
    public MySubClassMap()
    {
        // snip
    }

}

This maps the right tables and the foreign key, but no trace of on delete cascade. I'm sure I'm missing something, but can't find what.

Any idea ?

Thanks !


Solution

  • NHibernate implements the cascade in code. it may be possible to set the cascade on delete in hbm but not with FluentMappings. However you cann add the cascade rule with sql using NHibernate.Mapping.IAuxiliaryDatabaseObject