A quick response, from memory and without any form of verification:
 
ForeignKeyCascadeOnDelete means that the RDBMS should manage the cascade 
delete. AllDeleteOrphan means that NHibernate should manage the cascade 
delete (and sweep orphans found in memory).
 
So, I suspect that your database schema has a cascade delete on the 
relation from parent to child, but nothing on the relation between the 
child and the extended child. The delete will certainly fail if this is the 
case.
 
I have no idea how to propagate the ForeignKeyCascadeOnDelete all the way 
down to the extended child, so that everything "just works". Hand-modify 
the 2nd relation?
 
//Rasmus

Den onsdag den 6. august 2014 18.54.58 UTC+2 skrev pab:

>  Hi. I posted this same topic on stack overflow but there's no been 
> response as yet and unlikely to be one with the view count so I thought I 
> might try asking here. I have a model with a parent class that holds a 
> collection of subclassed children (using TablePerSubClass inheritance). 
> When attempting to to test cascading deletes by calling delete only on the 
> parent object I get a constraint error between the child table and its 
> joined-subclass table. To demonstrate...
>
>     public class ParentMap : ClassMap<Parent> {
>         public ParentMap() {
>             Id(x => x.Id);
>             HasMany(x => x.Children)
>                 .Cascade.AllDeleteOrphan()
>                 .ForeignKeyCascadeOnDelete()
>                 .Inverse();
>         }
>     }
>
>     public class ChildMap : ClassMap<Child> {
>         public ChildMap() {
>             Id(x => x.Id);
>             References(x => x.Parent).Not.Nullable();
>         }
>     }
>
>     public class ExtendedChildMap : SubclassMap<ExtendedChild> {
>         public ExtendedChildMap() {
>             Map(x => x.extraFeature);
>         }
>     }
>
>
> To test, I'm using NUnit with my testfixture beginning a new transaction 
> for each test setup, and rolling back the transaction for each teardown. 
> With the following test...
>
>
> using (var session = sessionFactory.OpenSession()) {
>     using (var transaction = session.BeginTransaction()) {
>
>         var p = new Parent();
>         var c1 = new Child() { Parent = p };
>         var c2 = new ExtendedChild() { Parent = p };
>
>         session.SaveOrUpdate(p);
>         session.SaveOrUpdate(c1);
>         session.SaveOrUpdate(c2);
>         Assert.IsTrue(session.Query<Parent>().Count() == 1);
>         Assert.IsTrue(session.Query<Child>().Count() == 2);
>         Assert.IsTrue(session.Query<ExtendedChild>().Count() == 1);
>
>         session.Delete(p);
>         Assert.IsTrue(session.Query<Parent>().Count() == 0);
>     }}
>  
>
> The test fails on the final assertion with
>
> The DELETE statement conflicted with the REFERENCE constraint 
> "FKDB46742824B330ED". The conflict occurred in database "testDB", table 
> "dbo.ExtendedChild", column 'Child_id'
>
>
> If the collection only holds the baseclass Child objects it works as 
> expected, but when a derived ExtendedChild is added the delete doesn't seem 
> to propogate to the baseclass. Feel like I'm missing something obvious here 
> but I've still not managed to solve this after a good while searching.
>
> Lastly, I'm also still not 100% clear on the functional differences 
> between Cascade.AllDeleteOrphan and ForeignKeyCascadeOnDelete... or more 
> precisely (ignoring the save/update part) what is the case that the former 
> doesn't handle and requires the latter to be specified? TIA.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/d/optout.

Reply via email to