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?