Hi again,
I've got a small issue using .NET Nullable types in ICriteria expressions. I have the following class (I've removed the ID/Version stuff for brevity):
Code:
Public Class Order
Private m_OrderDate As Nullable(Of DateTime)
Public Overridable Property OrderDate() As Nullable(Of DateTime)
Get
Return m_OrderDate
End Get
Friend Set(ByVal value As Nullable(Of DateTime))
m_OrderDate = value
End Set
End Property
End Class
The mapping file:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Northwind.Order, Northwind" table="`Order`" optimistic-lock="all" dynamic-update="true" dynamic-insert="false" select-before-update="true" lazy="true">
<id name="ID" column="`ID`" type="Integer">
<generator class="assigned" />
</id>
<version name="Version" column="`VERSION`" type="Int64" unsaved-value="-1" />
<property name="OrderDate" column="`OrderDate`" type="DateTime" />
</class>
</hibernate-mapping>
So here's the interesting bit. I can load the object (using ISession.get) from the database without a problem.
However, if I try to do a filtered search with expressions (using ICriteria.List), I get the following exception:
Quote:
A first chance exception of type 'Northwind.ApplicationException' occurred in Northwind.dll
Northwind.vshost.exe Error: 0 : Northwind.ApplicationException: There was a problem when loading [Northwind.Order] ---> NHibernate.ADOException: Unable to perform find ---> System.InvalidCastException: Specified cast is not valid.
at NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
at NHibernate.Loader.Loader.BindPositionalParameters(IDbCommand st, QueryParameters queryParameters, Int32 start, ISessionImplementor session)
at NHibernate.Loader.Loader.PrepareQueryCommand(SqlString sqlString, QueryParameters parameters, Boolean scroll, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
at NHibernate.Impl.CriteriaImpl.List()
I've read various posts about using the Nullables package, but I can't do that - my domain objects need to use standard .NET datatypes.
Does anyone have any ideas?
TIA.
Vij