NHibernate Fluently 异常 - 对象无法从 DBNull 转换为其他类型

NHibernate Fluently Exception - Object cannot be cast from DBNull to other types

我不可能传递解决这个问题所需的所有信息。

我需要提示、类似问题的解决方案...诸如此类。

当我解决它时,我会标记帮助我解决问题的答案以及post它是如何完成的。

感谢所有提供信息的人。


只有少数列被映射,Id 被设置为 "PK"。 我不知道发生了什么。

这就像有人在 NHibernate 上忘记检查 IsDbNull() 之前反射。

CLASS

public class BaseMap<T> : ClassMap<T> where T : IEntity
{
    public BaseMap()
    {
        Id(x => x.Id, "ID").GeneratedBy.TriggerIdentity();
    }
}

public class UsuarioMap : BaseMap<Usuario>
{
    public UsuarioMap()
    {
        //Indica qual a tabela deve ser utilizada.
        Table("FUNCIONARIO");
        Map(x => x.CodigoReduzido, "FUN_CODIGO");
        Map(x => x.CodPerfilBiomeek, "PER_CODIGO");
        Map(x => x.Local, "LOC_CODIGO");
        Map(x => x.Nome, "FUN_NOME");
        Map(x => x.DataInclusao, "FUN_DT_INC");
        Map(x => x.UsuarioInclusao, "FUN_FUN_INC");
    }
}

TABLE

异常

System.InvalidCastException: Object cannot be cast from DBNull to other types.
   at System.DBNull.System.IConvertible.ToDecimal(IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at NHibernate.Id.Insert.OutputParamReturningDelegate.ExecuteAndExtract(IDbCommand insert, ISessionImplementor session)
   at NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityIdentityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.Save(Object obj)

禁用的触发器是问题的原因

Id(x => x.Id, "ID").GeneratedBy.TriggerIdentity();

INSERT 之后禁用的触发器不生成 ID 和 "ID" 列 return 具有 DbNull 值.