Expression.Sql should support aliases other than {alias}
Description
Expression.Sql("") only allows use of the root alias using {alias}. It should allow usage of any subcriteria alias. Attached is a patch which implements this.
The patch is non-ideal in that it pokes a whole through to CriteriaImpl, which it probably should not do. I'm seeking advice on the best way to obtain the required information.
I ran into this issue as well...aliases should work the same way across the system.
Boris Drajer
April 9, 2012 at 10:46 AM
+1. This is important as a last-resort solution for all database-specific features that aren't supported in another way. Supporting a single alias here means supporting only the most trivial cases.
Note that the previous patches don't seem to resolve certain types of subqueries - if I'm not mistaken, it's the detached queries that don't work. For example, a query like
will fail to find mainQuery aliases referenced by sql_expression. Looking through the source, I have been able to find the way to traverse from the inner expression to the outer, but it involved a bit of reflection and a casting of interfaces to real types, so it's a bit of a hack. I'm including a patch as a proof of concept, but it needs to be worked on by someone who knows more about NH.
LarsL
November 11, 2009 at 5:17 AM
+1 Especially when working with legacy-databases it is often necessary to create custom sql-statements. It would be great if we could reuse the aliases there.
luis cornejo
October 28, 2008 at 11:34 PM
Also,
if it won't be implemented, can anyone suggest a way to get the right alias of subcriterias in there for custom sql use with criterias?
Expression.Sql("") only allows use of the root alias using {alias}. It should allow usage of any subcriteria alias. Attached is a patch which implements this.
The patch is non-ideal in that it pokes a whole through to CriteriaImpl, which it probably should not do. I'm seeking advice on the best way to obtain the required information.