开发者

how to dynamically break NHibernation cascade

The NHibernate cascade setting in the entity mapping is static. Is there anyway to dynamically disable the "cascade" setting in code to avoid expensive cascade operation in NHiberate during a bulky data transaction? We do not want to use stored procedures or native SQL because we need to have the entity changes captured by NHibernate开发者_如何学JAVA (audit).


It is not possible to disable cascading dynamically.

You can use a StatelessSession.

But if you sometimes don't need cascading in a particular relationship, just don't set it. Cascade is a nice feature to have, but it's not required to make things work.


you can build up a new sessionfactory using your mappings and interceptor but altering the mapping to disable cascading

var config = BuildConfiguration();
var classmapping = config.GetClassMapping("myentity");
classmapping.GetProperty("myprop").Cascade = "none";

var bulkinsertSf = config.BuildSessionFactory();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜