本文介绍了在 nhibernate 中刷新实体的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想刷新一个实体及其所有子集合.做这个的最好方式是什么?我说的是 nhibernate:)

I would like to refresh an entity and all its child collections. What is the best way to do this? I'm talking about nhibernate:)

我读过 session.Evict、session.Refresh...

I've read about session.Evict, session.Refresh...

但我仍然不确定是否这样做:

But I'm still not sure if doing like:

RefreshEntity<T>(T entity)
{
 session.Evict(entity);
 session.Refresh(entity);
}

完全按照我想要的方式工作

would work exactly how I want it to work

它会起作用吗?如果没有,我还能做什么?

Is it going to work? If not What else I can do?

推荐答案

Evict 后刷新可能不起作用.

Refresh after Evict probably won't work.

理论上,仅 Refresh 就足够了.但是,当子集合的元素被删除时,它存在已知问题.

Theoretically, Refresh alone should be enough. However, it has known issues when elements of child collections have been deleted.

Evict 后接 Get 通常可以完成任务.

Evict followed by Get usually gets things done.

这篇关于在 nhibernate 中刷新实体的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 04:00