开发者

NHibernate overwrite the concurrency in optimistic scenario

开发者 https://www.devze.com 2022-12-22 19:39 出处:网络
I have implemented optimistic locking for concurrency situations. I have used the version property in the mapping files to link to a integer.

I have implemented optimistic locking for concurrency situations. I have used the version property in the mapping files to link to a integer.

My aim is that if a user tried to save an out-of-date object, she will 开发者_如何学编程be given the option to overwrite changes.

I have easily managed to get the SaveOrUpdate to throw an exception, but how do I now override that so that if the user so wishes, the current object overwrites the existing persisted object, while still updating the version number, and without doing a manual member-wise copy of the variables into the non-stale object?

This seems like this is a regular logical scenario, but I don't see any built-in mechanism for this.So is this an anti-pattern?

Thanks for your help and insight.

Kind regards

LJ


I think you should look into the session.Merge method.

Jide

0

精彩评论

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