NHibernate动态更新无法更新拦截器中更改的数据
问题描述:
如果我设置dynamic-update = true我发现在我的拦截器中更新的字段没有包含在去到数据库的update语句中。当我将它设置为false时,包括时间戳的所有列都会更新。我真的想使用动态更新。NHibernate动态更新无法更新拦截器中更改的数据
public class Interceptor : EmptyInterceptor
{
public override Boolean OnFlushDirty(object entity, object id, object[] state,
object[] previousState, string[] propertyNames, IType[] types)
{
var auditEntity = entity as BaseAuditEntity;
if (auditEntity != null)
{
var now = DateTime.Now;
var index = Array.IndexOf(propertyNames, "LastModifiedTimestamp");
state[index] = now;
auditEntity.LastModifiedTimestamp = now;
}
return base.OnFlushDirty(entity, id, state, previousState, propertyNames, types);
}
}
我以为这条线可能会标记我最后修改的列为脏。
auditEntity.LastModifiedTimestamp = now;
有没有什么我应该在我的拦截器中将时间戳字段标记为脏?
答
API-Doc说:“如果用户以任何方式修改了currentState,则返回true”。
您是否试图返回true而不是调用空的基础实现?
public class Interceptor : EmptyInterceptor
{
public override Boolean OnFlushDirty(object entity, object id, object[] state,
object[] previousState, string[] propertyNames, IType[] types)
{
var auditEntity = entity as BaseAuditEntity;
if (auditEntity != null)
{
var now = DateTime.Now;
var index = Array.IndexOf(propertyNames, "LastModifiedTimestamp");
state[index] = now;
auditEntity.LastModifiedTimestamp = now;
return true;
}
return base.OnFlushDirty(entity, id, state, previousState, propertyNames, types);
}
}
工作。谢谢!我以为我已经尝试过,但最近我一直在尝试很多不同的东西。 – Jerry 2009-11-23 14:52:29