简体   繁体   中英

How to prevent NHibernate to load child collection in one-to-many relationship when removing parent

I have Company->Users one-to-many relationship and I would like users to be cascade deleted, when company is deleted. The problem is that NHibernate (accourding to console output: I have configured Nhibernate to log generated sql to console) first load the child collection and then performs delete on every child. How to configure NHibernate to cascade delete child collection without loading it?

Look at this answer here: https://stackoverflow.com/a/1323461/27343

There might be some space for optimization, but it is actually not that bad and in some cases even better to load children instead of trying to blindly execute some SQL delete statements.

NHibernate supports "on delete cascade" options

<key column="column" on-delete="cascade" />

but it works only under certain circumstances. It tells you when you load the mapping files.

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