OK, this was unexpected. The CLR has some magic for Nullable<T>, I just tried the wrong way:
An Expression.Constant that has an explicit type parameter works for comparing to null (same for lambda parameters): Expression.Constant(o, typeof(int?)) Without type parameter: Expression.Constant(o) รจ InvalidOperationException: The binary operator Equal is not defined for the types 'System.Int32' and 'System.Object'. Obviously, the CLR can't guess the argument's nullable nature from the boxed value. Maybe we can use that. I'll get back to you. Stefan From: [email protected] [mailto:[email protected]] On Behalf Of Patrick Earl Sent: Tuesday, December 07, 2010 5:20 PM To: [email protected] Subject: Re: [nhibernate-development] Fwd: NHibernate 3 GA, Linq and VB.NET Thanks for correcting me on the value/reference thing. I still don't understand the original comment that the nullable value cannot be used in an equality expression. As far as I can see, the example I posted does exactly what would be needed. Patrick Earl On Tue, Dec 7, 2010 at 9:16 AM, David Pfeffer <[email protected]<mailto:[email protected]>> wrote: Additionally, Nullable<T> == null syntax is, IIRC, syntactic sugar for Nullable<T>.HasValue. On Tue, Dec 7, 2010 at 11:13 AM, David Pfeffer <[email protected]<mailto:[email protected]>> wrote: Nullable<T> is defined as a struct, a value type. [SerializableAttribute] public struct Nullable<T> where T : struct, new()
