NHibernate PreUpdate 事件侦听器不持久化更改 [英] NHibernate PreUpdate event listener not persisting changes

查看:23
本文介绍了NHibernate PreUpdate 事件侦听器不持久化更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下 PreUpdate 事件监听器:

We have the following PreUpdate event listener:

public bool OnPreUpdate(PreUpdateEvent @event)
        {
            BaseBO entity = @event.Entity as BaseBO;
            if (entity == null)
                return false;

            var operatorName = "OpName";
            var utcDateTime = DateTime.Now.ToUniversalTime();

            Set(@event.Persister, @event.State, "ModifiedBy", "Fred & Barney");
            Set(@event.Persister, @event.State, "ModifiedDate", utcDateTime);

            entity.ModifiedBy = "fred & barney";
            entity.ModifiedDate = utcDateTime;

            return false;
        }

private void Set(IEntityPersister persister, object[] state, string propertyName, object value)
        {
            var index = Array.IndexOf(persister.PropertyNames, propertyName);
            if (index == -1)
                return;
            state[index] = value;
        }

Breakpoints on return 语句表明旧/新状态值和实体属性已更新为预期值.

Breakpoints on return statement indicate that the old / new state values and the entity properties have been updated to the expected values.

然而,运行 Sql profiler 显示 ModifiedDate/ModifiedBy 值没有更新.

However running Sql profiler shows that the ModifiedDate / ModifiedBy values are not updated.

如果我更新持久性代码并手动设置 ModifiedDate,Profiler 会显示正在更新的 ModifiedDate.

If I update the persistence code and set the ModifiedDate manually, Profiler shows the ModifiedDate being updated.

我们大多数实体的映射文件是:

The mapping file for the majority of our entities is:

<property name="ModifiedDate" insert="false" />

关于什么可能阻止事件侦听器设置的值传播到数据库的任何想法?

Any thoughts as to what could be preventing the values set by the event listener from being propogated to the database?

推荐答案

您的表映射中有动态更新吗?NHibernate 中有一个错误",它阻止 PreUpdate 和 PreInsert 与动态更新一起工作.请参阅 http://www.mail-archive.com/nhusers@googlegroups.com/msg13624.html

Do you have dynamic-update in your table mappings? There's a "bug" in NHibernate that prevents PreUpdate and PreInsert from working with dynamic-update. See http://www.mail-archive.com/nhusers@googlegroups.com/msg13624.html

这篇关于NHibernate PreUpdate 事件侦听器不持久化更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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