【问题标题】:Problem accessing previousState in OnFlushDirty() event of Castle ActiveRecord在 Castle ActiveRecord 的 OnFlushDirty() 事件中访问 previousState 时出现问题
【发布时间】:2008-09-29 18:14:38
【问题描述】:

我遇到了这个问题,我正在使用 Castle ActiveRecord,当我更新时,我会在 OnFlushDirty 事件中验证对象的更改。

但是,当我访问 previouState["MyProperty"] 时,它变为 null 并且我无法获取旧值。

你知道为什么吗?

这是代码;

    protected override bool OnFlushDirty(object id, System.Collections.IDictionary previousState, System.Collections.IDictionary currentState, NHibernate.Type.IType[] types)
    {
        StringBuilder errors = new StringBuilder();

        if (this._bankCode <= 0)
            errors.Append("Bank code is invalid" + Environment.NewLine);

        if (string.IsNullOrEmpty(this._name) || this._name.Trim().Length == 0)
            errors.Append("Name is invalid" + Environment.NewLine);

        //previousState["EnterpriseCode"] is always null
        if (previousState["EnterpriseCode"] != currentState["EnterpriseCode"])
        {
            if (this._enterpriseCode == 0)
                errors.Append("Enterprise code is invalid" + Environment.NewLine);
            else 

         ...

【问题讨论】:

    标签: activerecord castle


    【解决方案1】:

    我终于做到了,碰巧在hibernate中你必须使用merge()来使hibernate“加载”分离对象的previuos数据,在Castle中相当于SaveCopy()方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      • 2017-04-08
      相关资源
      最近更新 更多