Hi Chaps,
The good news is that I'm still here - we're past the initial 3 months
that iMeta originally provided, but I'm glad to say that the powers
that be are happy for me to continue to see this completed. The bad
news is that the last 3 or 4 weeks have been insane with other stuff
(particularly an office move, which we completed today), so things
haven't progressed much at all from my last update. I'm about to head
off on holiday for a couple of weeks, but when I return I will be back
onto my ASTs in anger, and hope to get things progressing along again.
In the meantime, I need some help. Consider the following query:
var query = from p in db.Products
join o in db.OrderLines.Where(ol => ol.UnitPrice > 5) on p.Id
equals
o.Product.Id
where p.Id ==
o.Product.Id
select p;
It might be a little contrived, but don't let that get in the way -
the general form is what's interesting. If I were mapping this to
SQL, I'd create something like this:
select *
from Products p
join
(
select * from OrderLines where UnitPrice > 5
) o on p.Id = o.ProductId
Again, don't take too much notice of the *exact* sql, I know it isn't
correct but it's the form that's important. In particular, the nested
select to get the subset of OrderLines that the query requests. In
SQL (for most databases, at least) this is fine, but it isn't
supported in HQL. In HQL (afaik), we can't do nesting within the
select or from / join clauses.
If we can't do nesting, then mapping arbritrary Linq expressions to
HQL is, I think, going to be a challenge. So there are three things
I'd like to ask:
* Am I wrong about the nested selects in HQL? I think not, since I've
just ported the parser and it doesn't support them :)
* If we can't do nested selects, does anyone fancy a stab at a general
purpose algorithm for mapping nested LINQ queries to "flattened" HQL
ones. I've not thought of a good one yet, and I've a gut feel that
it's going to be hard. Note that things like re-linq don't help here
- the AST that it creates still has nesting in place (I think)
* How much effort would be involved in adding nested selects into NH?
If this were in any way possible, it would get my vote - it both makes
the LINQ work easier, and makes HQL more powerful.
Whilst on holiday I'm only going to be online sporadically, so don't
be surprised if any questions to me take a while to answer! Looking
forward to hearing your responses...
Cheers,
Steve