No Cascade Delete-Orphan option?

140 views
Skip to first unread message

James Crowley

unread,
Sep 3, 2009, 5:10:43 PM9/3/09
to fluent-n...@googlegroups.com
I'm probably missing something blindingly obvious here, but is there
any reason why there is no delete-orphan option when setting the
cascade types?

Thanks

James

Mikael Henriksson

unread,
Sep 3, 2009, 6:04:38 PM9/3/09
to fluent-n...@googlegroups.com
.I believe what you are looking for is Cascade.AllDeleteOrphan()

James Crowley

unread,
Sep 4, 2009, 4:07:01 AM9/4/09
to fluent-n...@googlegroups.com
Hi Mikael,

thanks for the response. Unfortunately, that's the "all-delete-orphan"
option (which I'd normally use), but I need the "delete-orphan" option
(so it doesn't automatically persist inserts and updates). I'm having
to do a slightly nasty workaround as described here:
http://fgheysels.blogspot.com/2009/05/forcing-nhibernate-to-cascade-deletes.html

in order to be able to delete and then insert entities on a collection
with a unique constraint (that's not on its primary key).

Unless you have any suggestions on how else I might achieve this?

Many thanks,

James

2009/9/3 Mikael Henriksson <mik...@zoolutions.se>:
--
James Crowley
Managing Director
Developer Fusion - Connecting developers worldwide

Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH
mob: 07986 624128 web: http://www.developerfusion.com/

Mikael Henriksson

unread,
Sep 4, 2009, 6:33:35 AM9/4/09
to fluent-n...@googlegroups.com
As far as the NHibernate reference is concerned there is no cascade "delete-all-orphans" maybe cascade "delete" is the one you are after? Cascade.Delete() in fluent. If it's not supported in nhibernate it's not going to be supported in Fluent either.

Hudson Akridge

unread,
Sep 4, 2009, 8:40:17 AM9/4/09
to fluent-n...@googlegroups.com

James Crowley

unread,
Sep 4, 2009, 11:05:42 AM9/4/09
to fluent-n...@googlegroups.com
Hmm, I'm even more confused now!

Ayende makes reference to this way back in 2006:

http://ayende.com/Blog/archive/2006/12/02/NHibernateCascadesTheDifferentBetweenAllAlldeleteorphansAndSaveupdate.aspx

??

Thanks

James

2009/9/4 Hudson Akridge <hudson....@gmail.com>:

Stuart Childs

unread,
Sep 4, 2009, 1:22:52 PM9/4/09
to fluent-n...@googlegroups.com
Well, looking back as far as the 1.0.2 documentation, only the
following cascades are documented:

cascade="all|none|save-update|delete|all-delete-orphan"

I also found this comment from January 14: "Hmm.. I'm using NHibernate
2.2 and this happens: [MappingException: Unsupported cascade style:
delete-orphans]"
(here: http://stackoverflow.com/questions/444753/how-do-i-make-nhibernate-delete-child-refererences-when-i-delete-a-parent)

Now I suppose it's possible that they slipped in a delete-orphans
cascade and didn't tell anyone but I'd have to check the NH source to
find out.

Stuart Childs

unread,
Sep 4, 2009, 1:33:44 PM9/4/09
to fluent-n...@googlegroups.com
I just looked and here is the full cascade dictionary for NH 2.1 GA:
static CascadeStyle()
{
Styles["all"] = All;
Styles["all-delete-orphan"] = AllDeleteOrphan;
Styles["save-update"] = Update;
Styles["persist"] = Persist;
Styles["merge"] = Merge;
Styles["lock"] = Lock;
Styles["refresh"] = Refresh;
Styles["replicate"] = Replicate;
Styles["evict"] = Evict;
Styles["delete"] = Delete;
Styles["remove"] = Delete; // adds remove as a sort-of alias for delete...
Styles["delete-orphan"] = DeleteOrphan;
Styles["none"] = None;
}

Sure enough, "delete-orphan" is there, and it has a valid CascadeStyle
implementation:
[Serializable]
private class DeleteOrphanCascadeStyle : CascadeStyle
{
public override bool DoCascade(CascadingAction action)
{
return action == CascadingAction.Delete || action ==
CascadingAction.SaveUpdate;
}

public override bool ReallyDoCascade(CascadingAction action)
{
return action == CascadingAction.Delete;
}

public override bool HasOrphanDelete
{
get { return true; }
}
}

The question is now what to do about it. :)

James Crowley

unread,
Sep 4, 2009, 1:40:12 PM9/4/09
to fluent-n...@googlegroups.com
It's there.

NHibernate\Engine\CascadeStyle.cs

includes "delete-orphan" . I'm in the process of adding it to Fluent
NHibernate and checking that it works as expected.. I'm guessing it
only applies to collections, as with AllDeleteOrphan.

2009/9/4 Stuart Childs <chi...@gmail.com>:

James Crowley

unread,
Sep 4, 2009, 1:40:47 PM9/4/09
to fluent-n...@googlegroups.com
Sorry Stuart - crossed emails! Thanks for checking - 'tis good to know
I'm not going entirely mad ;)

2009/9/4 Stuart Childs <chi...@gmail.com>:

Paul Batum

unread,
Sep 4, 2009, 10:32:52 PM9/4/09
to fluent-n...@googlegroups.com
Did anyone else LOL when they saw methods with the names "DoCascade" and "ReallyDoCascade" ? :D

Mikael Henriksson

unread,
Sep 5, 2009, 5:01:15 AM9/5/09
to fluent-n...@googlegroups.com
Lol sorry i missed it was from the source code. Never mind my previous message!

On 9/5/09, Mikael Henriksson <mik...@zoolutions.se> wrote:
> I'd be really interested in knowing what reference you are referring
> to because I can't find it in the one i got with my download! :)
> --
> Sent from my mobile device
>

--
Sent from my mobile device

Mikael Henriksson

unread,
Sep 5, 2009, 4:59:10 AM9/5/09
to fluent-n...@googlegroups.com
I'd be really interested in knowing what reference you are referring
to because I can't find it in the one i got with my download! :)

On 9/5/09, Paul Batum <paul....@gmail.com> wrote:

Stuart Childs

unread,
Sep 5, 2009, 2:16:25 PM9/5/09
to fluent-n...@googlegroups.com
Just wait til you find the ReallyDoCascade().RightNow().YesImSerious() method chain. :P
Reply all
Reply to author
Forward
0 new messages