gpt4 book ai didi

c# - nhibernate 使用以前的状态创建

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:27 25 4
gpt4 key购买 nike

我有类似的东西

var productList = order.Products.TolIst();

我循环遍历 productList 并使用

更新每个产品
session.SaveOrUpdate(product);

但问题是,OnFlushDirty 函数中产品的先前状态为 null(这是有道理的)。

有没有办法管理/复制/注入(inject)以前的状态?

谢谢

最佳答案

这可能与分离对象更新有关。尝试阅读这个非常相似的故事:http://jamesfitzsimons.com/?p=152

问题总结:

... On investigation we realised that the previousState parameter passed into the onFlushDirty method of our interceptor was null. ...

解决方法:

The solution was to use the merge() method (new in NHibernate 2.0). Merge() checks the first level cache to see if an object with the given identifier has previously been loaded. If so it loads that object out of the first level cache and updates it’s properties using the detached object. This means that the session is now able to track the changes made to the object so that when the flush occurs the previousState is no longer null.

关于c# - nhibernate 使用以前的状态创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14624244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com