在 Castle ActiveRecord 的 OnFlushDirty() 事件中访问 previousState 时出现问题

发布于 2024-07-06 21:56:32 字数 993 浏览 5 评论 0原文

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

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

你知道为什么吗?

这是代码;

    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 

         ...

I have this problem, I'm using Castle ActiveRecord and when I update I verify changes in the object in the OnFlushDirty event.

However, when I access to the previouState["MyProperty"], it turns to be null and I can't get the old value.

Do you know why?

this is the code;

    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 

         ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅刃 2024-07-13 21:56:32

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

I finally made it, it happens that in hibernate you must use merge() to make that hibernate "loads" the previuos data of the detached object, in Castle the equivalent is the SaveCopy() method .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文