Restrictions is just a helper.
Restrictions.Eq is a one liner that does this:

    return new SimpleExpression(propertyName, value, " = ");

You can easily create your own helper, MyRestrictions with an Eq method that
returns AbstractCriterion with the following code:

    return value == null? Restrictions.Eq(propertyName, value) :
Restrictions.IsNull(propertyName);

It will do exactly what you want and you don't need patches or hacks of any
type, nor repeating code. Enjoy.

   Diego

On Mon, Dec 14, 2009 at 17:51, Christian <[email protected]> wrote:

> hi everyone,
>
> i was just running into a really annoying problem with nhibernate. if
> you pass a null value to Restrictions.Eq() it gets translated to
> "WHERE ColumnName = NULL" instead of "WHERE ColumnName IS NULL".
>
> as far as I have read in documentations, "= NULL" per specification
> ALWAYS returns false so in my mind, this is a bug in (N)Hibernate.
>
> there's also already an open bug in Hibernate:
> http://opensource.atlassian.com/projects/hibernate/browse/HHH-2951
>
> any chance to get this bug resolved in near future? or is there any
> other simple solution? i don't want to add NULL-checks before every
> call to Restrictions.Eq().
>
> everything else with NH worked quite well, so I don't want to change
> the code myself just for this little patch, because this would make
> updating NHibernate harder...
>
> ps: setting "set ansi_nulls off" is not an option because this isn't
> ansi standard.
>
> thanks for your help!
>
> regards, christian
>
> --
>
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
>

--

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