public void AddOrderBy(QuerySelect sql)
			{
				if (persisters == null)
				{
					return;
				}

				for (int i = 0; i < count; i++)
				{
					IQueryableCollection persister = (IQueryableCollection) persisters[i];
					if (persister.HasOrdering)
					{
						sql.AddOrderBy(persister.GetSQLOrderByString(names[i]));
					}
				}
			}
		private void RenderSql()
		{
			int rtsize;
			if( returnedTypes.Count == 0 && scalarTypes.Count == 0 )
			{
				//ie no select clause in HQL
				returnedTypes = fromTypes;
				rtsize = returnedTypes.Count;
			}
			else
			{
				rtsize = returnedTypes.Count;
				foreach( string entityName in entitiesToFetch )
				{
					returnedTypes.Add( entityName );
				}
			}

			int size = returnedTypes.Count;
			persisters = new IQueryable[size];
			names = new string[size];
			owners = new int[size];
			suffixes = new string[size];
			includeInSelect = new bool[size];
			for( int i = 0; i < size; i++ )
			{
				string name = ( string ) returnedTypes[ i ];
				//if ( !IsName(name) ) throw new QueryException("unknown type: " + name);
				persisters[ i ] = GetPersisterForName( name );
				suffixes[ i ] = ( size == 1 ) ? String.Empty : i.ToString() + StringHelper.Underscore;
				names[ i ] = name;
				includeInSelect[ i ] = !entitiesToFetch.Contains( name );
				if( includeInSelect[ i ] )
				{
					selectLength++;
				}
				if( name.Equals( collectionOwnerName ) )
				{
					collectionOwnerColumn = i;
				}
				string oneToOneOwner = (string) oneToOneOwnerNames[ name ];
				owners[ i ] = oneToOneOwner == null ? -1 : returnedTypes.IndexOf( oneToOneOwner );
			}

			if ( ArrayHelper.IsAllNegative( owners ) )
			{
				owners = null;
			}

			string scalarSelect = RenderScalarSelect(); //Must be done here because of side-effect! yuck...

			int scalarSize = scalarTypes.Count;
			hasScalars = scalarTypes.Count != rtsize;

			returnTypes = new IType[scalarSize];
			for( int i = 0; i < scalarSize; i++ )
			{
				returnTypes[ i ] = ( IType ) scalarTypes[ i ];
			}

			QuerySelect sql = new QuerySelect( factory.Dialect );
			sql.Distinct = distinct;

			if( !shallowQuery )
			{
				RenderIdentifierSelect( sql );
				RenderPropertiesSelect( sql );
			}

			if( CollectionPersister != null )
			{
				sql.AddSelectFragmentString( collectionPersister.SelectFragment( fetchName ) );
			}
			if( hasScalars || shallowQuery )
			{
				sql.AddSelectFragmentString( scalarSelect );
			}

			// TODO: for some dialects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings
			MergeJoins( sql.JoinFragment );

			sql.SetWhereTokens( whereTokens );

			sql.SetGroupByTokens( groupByTokens );
			sql.SetHavingTokens( havingTokens );
			sql.SetOrderByTokens( orderByTokens );

			if( collectionPersister != null && collectionPersister.HasOrdering )
			{
				sql.AddOrderBy( collectionPersister.GetSQLOrderByString( fetchName ) );
			}

			scalarColumnNames = GenerateColumnNames( returnTypes, factory );

			// initialize the set of queried identifer spaces (ie. tables)
			foreach( string name in collections.Values )
			{
				IQueryableCollection p = GetCollectionPersister( name );
				AddQuerySpace( p.CollectionSpace );
			}
			foreach( string name in typeMap.Keys )
			{
				IQueryable p = GetPersisterForName( name );
				object[] spaces = p.PropertySpaces;
				for ( int i=0; i < spaces.Length; i++ )
				{
					AddQuerySpace( spaces[ i ] );
				}
			}

			sqlString = sql.ToQuerySqlString();

			try
			{
				if( holderClass != null )
				{
					holderConstructor = ReflectHelper.GetConstructor( holderClass, returnTypes );
				}
			}
			catch( Exception nsme )
			{
				throw new QueryException( "could not find constructor for: " + holderClass.Name, nsme );
			}

			if ( hasScalars )
			{
				actualReturnTypes = returnTypes;
			}
			else
			{
				actualReturnTypes = new IType[ selectLength ];
				int j = 0;
				for( int i = 0; i < persisters.Length; i++ )
				{
					if ( includeInSelect[ i ] )
					{
						actualReturnTypes[ j++ ] = NHibernateUtil.Entity( persisters[ i ].MappedClass ) ;
					}
				}
			}
		}