简体   繁体   中英

Fluent NHibernate cascading delete convention for aggregate roots

Question is: how to write convention that prevents deleting entity reference if it inherits from type Root ?


I'm using fluent nhibernate and it's auto mapping feature. Turned on cascading delete by default.

Everything was really cool until I finally hit case when I need to actually delete aggregate root that references another one.

I got roots User and Application . User registers Applications . If it's registered by mistake, there is small time gap in which User with role Admin can remove it (I'm kind a sure I won't ever need that data).

When User removes Application , because of cascading delete, nhibernate removes User itself (what an irony...).


I'm unsure how to specify SaveUpdate cascading for Application->User association only:

替代文字


Does the trick:

m.References(x=>x.RegisteredBy).Cascade.SaveUpdate(); //RegisteredBy.Type==User

Additionally, told fnh where to look for overrides:

var m=new AutoPersistenceModel(storeCfg);
m.UseOverridesFromAssembly(assembly);

You can override behaviour of cascading for Application->User association. You need to set SaveUpdate() instead of all-delete-orphan. To do this you will need to implement IAutomappingOverride<Application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM