NH 3 Linq Query with Contains(IQueryable) clause

83 views
Skip to first unread message

John Surcombe

unread,
Nov 5, 2010, 7:21:58 AM11/5/10
to nhusers
Using NH3 beta 2, I'm trying to do a SELECT where the WHERE clause
contains a subquery, as follows:

--------------
var ordersSubQuery = from o in Sess.Query<Order>()
where o.Customer.Id == 12345
select o;

var firstLines = from l in Sess.Query<Line>()
where ordersSubQuery.Contains(l.Order)
&& l.LineNumber == 1
select l;

var results = firstLines.ToList();
--------------

This executes, but it returns the first line of every order in the
database, not just those for the customer with Id 12345. In other
words, the where clause in ordersSubQuery gets ignored.

However, if I dispense with the separate ordersSubQuery variable, and
write the subquery inline, like this, then it works:

--------------
var firstLines = from l in Sess.Query<Line>()
where (from o in Sess.Query<Order>()
where o.Customer.Id == 12345
select o).Contains(l.Order)
&& l.LineNumber == 1
select l;

var results = firstLines.ToList();
--------------

I know there are lots of other ways I can do this - like using
QueryOver instead. However, I'm most interested to know why the first
approach doesn't work? Is it possible that it will be supported in
future? Or am I hitting some limitation of LINQ here?

Stefan Wenig

unread,
Nov 11, 2010, 5:39:28 AM11/11/10
to nhusers
I created an issue for re-linq: https://www.re-motion.org/jira/browse/RM-3474

When this is implemented, upgrading NH to the latest build of re-linq
should handle your queries as expected.

HTH,
Stefan

Meir

unread,
Dec 1, 2010, 4:03:41 PM12/1/10
to nhusers
Is there an update on this? I running into the same problem with the
latest NH 3.0-CR1.

Thanks!
Meir

Stefan Wenig

unread,
Dec 2, 2010, 3:25:11 AM12/2/10
to nhusers
Use the Jira-Link to track it. When finished, someone needs to update
the re-linq assembly in NH.
HTH, Stefan
> > > future? Or am I hitting some limitation of LINQ here?- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
Reply all
Reply to author
Forward
0 new messages