是否有ISession.Merge()的替代方法,在使用乐观锁定时不会抛出该替代方法? [英] Is there an alternative to ISession.Merge() that doesn't throw when using optimistic locking?
问题描述
我一直在尝试使用ISession.Merge()来保持两个会话之间的一致性,但是当合并的实例的Version属性高于会话中加载的实例的Version属性时,它会失败(带有StaleObjectStateException).
I've been trying to use ISession.Merge() to keep coherence between two sessions, but it fails when the merged instance has a higher Version property than the one loaded in the session (with a StaleObjectStateException).
当版本"字段不匹配时,是否有其他可行的方法?
Is there an alternative method that would work when the Version fields do not match ?
推荐答案
似乎没有任何方法可以安全地在会话之间合并实体,至少使用乐观锁定是可以的.
There doesn't seem to be any way to safely merge entities between sessions, at least with optimistic-locking.
我要使用另一种模式:每个会话都有每个实体的自己的副本,并且我根据需要在每个会话上refresh()
实例.这增加了内存使用和数据库往返的开销,但似乎可行.
I'm going with another pattern: each session has its own copies of each entity, and I refresh()
the instances on each session as needed. This has added overhead in memory usage and round-trips to the DB, but it seems to work.
这篇关于是否有ISession.Merge()的替代方法,在使用乐观锁定时不会抛出该替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!