private void FlattenSubQuery(SubQueryExpression subQueryExpression, MainFromClause fromClause,
                                     QueryModel queryModel)
        {
            // Create a new client-side select for the outer
            // TODO - don't like calling GetGenericArguments here...
            var clientSideSelect = new ClientSideSelect(new NonAggregatingGroupBySelectRewriter().Visit(queryModel.SelectClause.Selector, subQueryExpression.Type.GetGenericArguments()[0], queryModel.MainFromClause));

            // Replace the outer select clause...
            queryModel.SelectClause = subQueryExpression.QueryModel.SelectClause;

            MainFromClause innerMainFromClause = subQueryExpression.QueryModel.MainFromClause;

            CopyFromClauseData(innerMainFromClause, fromClause);

            foreach (var bodyClause in subQueryExpression.QueryModel.BodyClauses)
            {
                queryModel.BodyClauses.Add(bodyClause);
            }

            // Move the result operator up
            if (queryModel.ResultOperators.Count != 0)
            {
                throw new NotImplementedException();
            }

            queryModel.ResultOperators.Add(new NonAggregatingGroupBy((GroupResultOperator)subQueryExpression.QueryModel.ResultOperators[0]));
            queryModel.ResultOperators.Add(clientSideSelect);
        }
		private void FlattenSubQuery(SubQueryExpression subQueryExpression, MainFromClause fromClause,
		                             QueryModel queryModel)
		{
			// Create a new client-side select for the outer
			// TODO - don't like calling GetGenericArguments here...
			var clientSideSelect = new ClientSideSelect(new NonAggregatingGroupBySelectRewriter().Visit(queryModel.SelectClause.Selector, subQueryExpression.Type.GetGenericArguments()[0], queryModel.MainFromClause));

			// Replace the outer select clause...
			queryModel.SelectClause = subQueryExpression.QueryModel.SelectClause;

			MainFromClause innerMainFromClause = subQueryExpression.QueryModel.MainFromClause;

			CopyFromClauseData(innerMainFromClause, fromClause);

			foreach (var bodyClause in subQueryExpression.QueryModel.BodyClauses)
			{
				queryModel.BodyClauses.Add(bodyClause);
			}

			// Move the result operator up 
			if (queryModel.ResultOperators.Count != 0)
			{
				throw new NotImplementedException();
			}

			queryModel.ResultOperators.Add(new NonAggregatingGroupBy((GroupResultOperator) subQueryExpression.QueryModel.ResultOperators[0]));
			queryModel.ResultOperators.Add(clientSideSelect);
		}