【问题标题】:Why is my Fluent nHibernate repository (randomly) updating my domain entities?为什么我的 Fluent nHibernate 存储库(随机)更新我的域实体?
【发布时间】:2010-12-13 04:33:53
【问题描述】:

我们在我正在处理的 .net MVC 项目中使用 Fluent nHibernate 存储库模型。在运行 sql 配置文件以检查改进区域时,我们注意到一些对象在没有显式保存的情况下被更新。有人知道为什么 nHibernate 在我选择对象时会选择更新它吗?

类:

public class Request : DomainEntity
    {
        public virtual string Code { get; set; }

        public virtual string PartCode { get; set; }

        public virtual string Description { get; set; }

        public virtual int Quantity { get; set; }

        public virtual decimal Price { get; set; }

        public virtual DateTime DateRecieved { get; set; }
    }

示例用法:

var request = _repository.Query<Request>().Where(x => x.OemCode == "TEST").FirstOrDefault();

在使用不同的请求代码运行此代码后,我们的跟踪通常会发现看似随机的更新。有什么想法吗?

【问题讨论】:

    标签: .net sql model-view-controller fluent-nhibernate


    【解决方案1】:

    来自 HNhibernate documentation:

    ISession 会不时地 执行所需的 SQL 语句 同步 ADO.NET 连接的 状态与持有的对象的状态 在记忆中。这个过程,flush,发生 默认在以下几点

    • 来自 Find() 或 Enumerable() 的某些调用
    • 来自 NHibernate.ITransaction.Commit()
    • 来自 ISession.Flush()

    您可以通过设置 ISession.FlushMode 属性来覆盖此行为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多