我可以配置一个 NHibernate 命名过程以在加载对象时跳过某些属性吗?这些不是我想忽略的表中的列;它们是对象上与列不对应的属性,我想在使用命名过程时将它们保留为空。(在其他情况下,我确实想填充这些属性)。
我有一个 Inspection 对象,它具有从 SQL 表中读取的许多属性,以及一个使用公式计算的属性:
...
<property name="InspectionDate" type="DateTime" not-null="false" />
<property name="LastCompletedDate" type="DateTime" not-null="false"
formula="(select max(.....long formula.....)"/>
...
当 NHibernate 加载检查时,这可以正常工作。当我使用存储过程获取检查列表时,问题就来了:
<sql-query name="GetOverdueInspection">
<return class="Inspection" />
exec dbo.usp_GetOverdueInspection :dueDate
</sql-query>
这会引发异常:
10011 [10] INFO NHibernate.Loader.Loader (null) - exec dbo.usp_GetOverdueInspection @p0
NHibernate: exec dbo.usp_GetOverdueInspection @p0; @p0 = '4/29/2013 7:23:41 PM'10846 [10]
WARN NHibernate.Util.ADOExceptionReporter (null) - System.ArgumentNullException: Value cannot be null.
Parameter name: fieldName
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
at NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session)
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, BooleanreturnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
10849 [10] ERROR NHibernate.Util.ADOExceptionReporter (null) - Value cannot be null.
Parameter name: fieldName
使用此命名查询时,如何告诉 NHibernate 将 LastCompletedDate 保留为空?