开发者

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 ne开发者_Go百科ed 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:

Fluent NHibernate cascading delete convention for aggregate roots


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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜