nHibernate Cascade deletes parent

Posts   
 
    
tknuts
User
Posts: 13
Joined: 28-Jun-2010
# Posted on: 06-Mar-2014 14:47:14   

We have a simple relation from Member to MemberType, the FK on Member to MemberType is MemberTypeId.

In the designer there is no Cascade deletion configured(should never delete parent anyway)

Here is a snippet of the generated code og MemberMap:

            References(x=>x.MemberType)
                .Access.CamelCaseField(Prefix.Underscore)
                .Cascade.All()
                .Fetch.Select()
                .Columns("`MemberTypeID`");

Where does the .Cascade.All() come from, what it actually does is deleting the MemberType record along with the Member record :-( Reallly critical.

We have the latest 4.1 release of LLBLGen designer. Anyone know what to do ?

If we manually remove the .Cascade.All() line from MemberMap file, the parent is not deleted.

One more thing. Is it possible to expose the Member.MemberTypeId on generated code? it's a hazzle to load MemberType in order to store the Member.

Regards, Thomas

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Mar-2014 18:16:18   

Could you please share a repro LLBLGen project file?

tknuts
User
Posts: 13
Joined: 28-Jun-2010
# Posted on: 06-Mar-2014 22:36:58   

Hi

I can send you the real project file. Where can i send it to, in order not to expose it all over :-)

Regards, Thomas

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Mar-2014 06:54:35   

Go to Project->Settings->NHibernate. Then you can set these settings (ref...):

SingleEntityNavigatorCascadeTypeDefault. The cascade attribute to set for navigator mappings which represent a single entity. Default value: none

CollectionNavigatorCascadeTypeDefault. The cascade attribute to set for navigator mappings which represent a set/collection. Default value: all-delete-orphan

Then re-generate code. You also can set them to none. The first one is for single navigator, the other one is for collection navigator. You also could set those setting per-navigator basis: Edit your Entity, then go to 'Code gen. info' sub-tab, select the navigator on the element selector and set the value for that setting.

About the other question: Fluent NHibernate doesn't support fk fields. You should do:

member.MemberType.MemberTypeId = foo; 
David Elizondo | LLBLGen Support Team
tknuts
User
Posts: 13
Joined: 28-Jun-2010
# Posted on: 20-Mar-2014 16:34:57   

That seems to work, but now we have an issue, where we have a 1:1 relation with Cascade delete enabled in LLBGen and database, but in the generated nHibernate code it does not set it to Cascade delete :-( In the mapping file it's Cascade.None

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Mar-2014 08:22:41   

What are the value of those settings in that case?

David Elizondo | LLBLGen Support Team