Raw SQL in Criteria improvement

Jerome Haltom <[email protected]> Wed, 06 Aug 2008 14:35:48 -0500
Newsgroups gmane.comp.windows.dotnet.nhibernate.devel
Message-ID <[email protected]>
Howdy. Looks like when using Expression.Sql with a the criteria API, you
can only use {alias} to substitute the name of the root table name. This
sucks! Since I don't like this so much, I want to fix it.

So I did!

The fix is so small, I just wanted to shove it to the list and see if
anybody minds checking it out and committing it.

Now, the cast to (CriteriaImpl) sucks. But I don't know how to do it
properly. I'm sure there's someway, right? :)

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Nhibernate-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nhibernate-development
patch.txt (text/x-patch, 981 B)
--- C:\Users\jhaltom\AppData\Local\Temp\SQLCriterion.cs-revBASE.svn001.tmp.cs	Wed Aug  6 14:30:58 2008
+++ C:\Development\ISIS-3\vendor\NHibernate\src\NHibernate\Expression\SQLCriterion.cs	Wed Aug  6 14:31:20 2008
@@ -1,6 +1,8 @@
 using System;
 using System.Collections;
+
 using NHibernate.Engine;
+using NHibernate.Impl;
 using NHibernate.SqlCommand;
 using NHibernate.Type;
 
@@ -32,7 +34,10 @@
 
 		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
 		{
-			return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria));
+            SqlString s = _sql;
+            foreach (ICriteria c in ((CriteriaImpl)criteria).IterateSubcriteria())
+                s = s.Replace("{" + c.Alias + "}", criteriaQuery.GetSQLAlias(c));
+            return s.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria));
 		}
 
 		public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)