Hi Jim,
It's not a bug, it's by design. The QueryOver API uses the explicit
Restrictions.IsNull for that construct, so you need to do something like:
return
_session.QueryOver<Theme>()
.Where(t => t.Name == name)
.And(Restrictions.Or(
Restrictions.On<Theme>(t => t.User).IsNull,
Restrictions.Where<Theme>(t => t.User == user))
.SingleOrDefault();
http://216.121.112.228/browse/NH-2152
This is a not uncommon request, however the opaqueness of the API is deliberate
(the API is meant to mirror the way SQL will be generated, not hide it from the
user). In addition, this is the way that ICriteria behaves (which QueryOver is
built upon).
I have changed the existing issue to a feature request. Please vote for the
issue, and I'll see how much work it is to implement the feature.
Cheers,
Richard
From: Diego Mijelshon
Sent: Saturday, April 03, 2010 10:42 PM
To: nhusers
Subject: Re: [nhusers] QueryOver - Emits "MyProperty = null" instead of
"MyProperty is null"
It looks like a bug... or a very non-intuitive behavior.
You should open an Issue at http://jira.nhforge.org/
Diego
On Sat, Apr 3, 2010 at 18:03, Jim Geurts <[email protected]> wrote:
Hey guys,
I'm using the QueryOver api like:
private Theme GetThemeByName(string name, User user) {
return _session.QueryOver<Theme>().Where(x => x.Name == name &&
(x.User == null || x.User == user)).SingleOrDefault();
}
Behind the scenes, it is generating sql similar to:
SELECT this_.ThemeId as ThemeId7_0_,
this_.Name as Name7_0_,
this_.UserId as UserId7_0_
FROM pm_Themes this_
WHERE this_.IsDeleted = 0 /* @p0 */
and (this_.Name = 'Test Theme-asfdyT6W' /* @p1 */
and (this_.UserId = NULL /* @p2 */
or this_.UserId = 691 /* @p3 */))
You'll notice that it uses an equal sign instead of the keyword "is"
for the UserId check. I'm using the MsSql2008Dialect dialect. Is
this an nhibernate configuration issue, a bug on my end, or a bug with
the QueryOver api?
Thanks
Jim
--
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.
--
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.
--
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.