Running the following NHibernate Linq query:

           Session.Linq<MyEntity>.Select(x =>
x.NullableMoneyProperty).FirstOrDefault();


I receive the following exception:

           NHibernate.Exceptions.GenericADOException: Unable to
perform find[SQL: SQL not available] ---> System.ArgumentException:
The value "" is not of type "System.Nullable`1[Money]" and cannot be
used in this      generic collection. Parameter name: value



This occurs when the select statement returns a null column (as
opposed to not returning anything).

I can fix it by adding a check that the property is not null in the
query, but I believe the behaviour is not obvious.


I think my MoneyUserType is doing the right thing:

        public object NullSafeGet(IDataReader rs, string[] names,
object owner)
        {
            if (rs == null) return null;
            if (rs.IsDBNull(rs.GetOrdinal(names[0]))) return null;
            var val = (decimal)NHibernateUtil.Decimal.NullSafeGet(rs,
names[0]);
            return new Money(val);
        }


Do you think this a bug with my code, or a deficiency of Linq ->
NHibernate?

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to