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

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

问题描述

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

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天全站免登陆