NHibernate更新未更改的记录 [英] NHibernate updates unchanged records

查看:59
本文介绍了NHibernate更新未更改的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更新(刷新)从数据库nHibernate检索到的记录列表中的一条记录时,将对原始列表中的所有记录进行版本控制.

When I update (with a flush) one record in a list of records retrieved from the database nHibernate is versioning all of the records that were in the original list.

从数据库中检索记录列表:

Retrieving a list of records from the database:

using(UnitOfWork.Start())
{
   queuedJobs = aJobServiceManager.GetAllJobs().Where(aJob => aJob.Status == PricingStatus.QUEUED).ToList();
}

/* Do some work on the record*/
using(UnitOfWork.Start())
{
   //aJob is a record from queuedJobs.
   aJobServiceManager.Save(aJob);
   //When Flush is called I'm expecting only aJob to be updated in the database.
   //aJob is correctly updated BUT
   //All the other records in queuedJobs are also updated (their version field is incremented).
   UnitOfWork.Current.Flush();
}

为什么nHibernate在未更改所有记录时会更新它们,以及如何停止这种行为?

Why is nHibernate updating all the records when they haven't changed and how do you stop this behavior?

推荐答案

这很可能是您遇到的问题:

This is most likely the problem you're running into: http://nhibernate.info/blog/2008/10/20/how-test-your-mappings-the-ghostbuster.html

这将有助于查看您的作业映射文件.如果您正在做类似的事情

It would help to see your mapping file for job. If you're doing something like

<property name="Status" type="int" /> 

Status实际上是StatusEnum的地方,最终会出现重影.

Where Status is actually StatusEnum you'll end up with ghosting.

这篇关于NHibernate更新未更改的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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