NHibernate:有没有办法将一个对象标记为不脏? [英] NHibernate: is there a way to mark an object as NOT dirty?

查看:82
本文介绍了NHibernate:有没有办法将一个对象标记为不脏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一种情况,我需要使用自定义SQL加载对象图的一部分(出于性能原因).因此,我使用自定义SQL(ISession.CreateSQLQuery())加载了此集合,然后将该列表分配给另一个实体对象上的属性.

I have a situation where I need to load part of an object graph using custom SQL (for performance reasons). So I load up this collection using my custom SQL (ISession.CreateSQLQuery()) and then I assign that list to a property on another entity object.

问题在于,当我将列表分配给属性时,它会使该实体与列表中的所有对象一起变脏,因此当我去保存对象时,它会进行数百次查询来保存整个列表.有没有一种方法可以指定一个对象是否脏(在我自己加载它之后)?

The problem is that when I assign the list to the property, it makes that entity dirty along with all of the objects in the list, so when I go to save the object, it does hundreds of queries to save the entire list. Is there a way that I can specify that an object is NOT dirty (after I load it up myself)?

(是的,我知道我可以关闭cascade ="save-update",但是如果可以避免的话,我真的不想这样做.)

(Yeah, I know I could turn off cascade="save-update", but I really don't want to have to do that if I can avoid it.)

推荐答案

我认为有逐出实体的功能.

这意味着它不再与NHibernate连接.

That means it is not connected to NHibernate anymore.

已更新:

  • 如果您希望NHibernate 管理该对象,即检测该对象是否脏,则对其进行管理.
  • 如果没有,请Evict()对其进行管理.您仍然可以手动保存它,依此类推,只是它不会自动为您完成.
  • If you want NHibernate to manage the object, ie detect if it is dirty, then keep it managed.
  • If not, Evict() it, it won't be managed. You can still save it manually and so on, it's just that it won't be done automatically for you.

自动和手动 ...

请注意,您仍然可以通过各种方式坚持下去,例如手动保存父实体,一组子实体等等……仍然有很多可能.

Note that you can still persist in various ways, like saving manually the parent entity, a Set of child entities and so on... Many things are still possible.

这篇关于NHibernate:有没有办法将一个对象标记为不脏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆