2

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 !

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85
  • What do you mean by "this maps the right tables and the foreign key, but no trace of on delete cascade?" Where are you looking for the cascade? – Rich Tebb Oct 03 '12 at 16:33
  • @RichTebb: I mean that when using this FNH mapping to generate a new DB, it recreates the tables as they exist in the current DB, but not the existing on delete cascade I mentioned. This model is a legacy one that I just would like to recreate as it exists today using FNH mappings. – xlecoustillier Oct 24 '12 at 07:25
  • I've never used DB cascades myself (NHibernate has its own ideas about cascading and I didn't want to have them clash). But this answer might be related: http://stackoverflow.com/a/4470964/260213 – Rich Tebb Oct 26 '12 at 13:42
  • I have the same problem, Did you find the answer? Could help me? – Only a Curious Mind Feb 13 '17 at 16:13

1 Answers1

0

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

Firo
  • 30,626
  • 4
  • 55
  • 94