我可以使用 nhibernate 判断一个属性是否脏吗? [英] Can I tell if a property is dirty using nhibernate?

查看:23
本文介绍了我可以使用 nhibernate 判断一个属性是否脏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以使用 NHibernate 判断对象上的特定属性是否脏(即该属性与存储在 DB 上的属性不同)?

Does anyone know if it is possible to tell if a specific property on an object is dirty (i.e. the property is different to the one stored on the DB) using NHibernate?

这个问题的背景是我将拥有一个具有(相对)大量属性的对象.我需要能够将一个参数(字符串)传递给一个函数,该函数将确定该特定属性在页面的生命周期内是否发生了变化.

The background to this question is that I will have an object with a (relatively) large number of properties on it. I need to be able to pass a parameter (string) to a function that will determine if that specific property has changed during the lifetime of the page.

如果需要,我可以创建对象的副本并在页面生命周期结束时使用反射来检查值,但我不愿意这样做.如果 NHibernate 能简单地告诉我一个属性是否脏,那就太好了.

If I need to I can create a copy of the object and use reflection at the end of the page lifecycle to check the value, but I am reluctant to do this. It would be great if NHibernate could simply tell me if a property was dirty.

谢谢

推荐答案

目前无法通过 nHibernate(或 Hibnernate,AFAIK)API 获得.您可以通过存储对象加载到会话时的状态来自己编写类似的内容,然后比较它们.

That is not currently available through the nHibernate (or Hibnernate, AFAIK) API. You could write something like this yourself by storing the state of the objects when they're loaded into session, then compare them.

注意:我自己还没有看到这个,但是,如果您还没有锁定 ORM 选择,您应该查看 Subsonic.许多脏状态在对象本身内进行跟踪,您可以确定特定属性是否脏.

NOTE: I haven't seen this for myself, but, if you haven't locked into an ORM choice, you should look at Subsonic. A lot of the dirty status is tracked within the objects themselves, and you'd be able to determine if a particular property is dirty.

这篇关于我可以使用 nhibernate 判断一个属性是否脏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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