private CodeSnippetExpression RewriteComprehensionExpression(CodeQueryExpression queryExpression)
            {
                using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                {
                    if (queryExpression.From != null)
                    {
                        sw.Write("(");
                        sw.Write("from " + queryExpression.InputParameterName + " in ");
                        this.generator.GenerateCodeFromExpression(queryExpression.From, sw, null);
                        sw.WriteLine();
                    }
                    
                    if (queryExpression.OrderByKeySelectors.Count != 0)
                    {
                        sw.Write("orderby ");
                        for (int i = 0; i < queryExpression.OrderByKeySelectors.Count; i++)
                        {
                            var keySelector = queryExpression.OrderByKeySelectors[i];
                            this.generator.GenerateCodeFromExpression(keySelector, sw, null);
                            if (queryExpression.AreDescending[i])
                            {
                                sw.Write(" descending");
                            }
                            
                            if (i != queryExpression.OrderByKeySelectors.Count - 1)
                            {
                                sw.Write(", ");
                            }
                        }
                        
                        sw.WriteLine();
                    }
                    
                    if (queryExpression.Where != null)
                    {
                        sw.Write("where ");
                        this.generator.GenerateCodeFromExpression(queryExpression.Where, sw, null);
                        sw.WriteLine();
                    }

                    if (queryExpression.GroupByKeySelector != null)
                    {
                        sw.Write("group " + queryExpression.InputParameterName + " by ");
                        this.generator.GenerateCodeFromExpression(queryExpression.GroupByKeySelector, sw, null);
                        sw.Write(" into " + queryExpression.GroupParameterName);
                        sw.WriteLine();
                    }

                    if (queryExpression.Select != null)
                    {
                        sw.Write("select ");
                        this.generator.GenerateCodeFromExpression(queryExpression.Select, sw, null);
                        sw.Write(")");
                        sw.WriteLine();
                    }
                    else
                    {
                        if (queryExpression.GroupByKeySelector != null)
                        {
                            sw.Write("select " + queryExpression.GroupParameterName);
                            sw.Write(")");
                        }
                        else
                        {
                            sw.Write("select " + queryExpression.InputParameterName);
                            sw.Write(")");
                        }
                        
                        sw.WriteLine();
                    }

                    return new CodeSnippetExpression(sw.ToString());
                }
            }
 /// <summary>
 /// Get the group Parameter Name
 /// </summary>
 /// <param name="codeQuerySource">Input code query Source</param>
 /// <returns>Group Parameter Name</returns>
 protected string GetGroupParameterName(CodeQueryExpression codeQuerySource)
 {
     bool shouldCreateNewGroupParameter = codeQuerySource == null || codeQuerySource.GroupByKeySelector != null;
     if (shouldCreateNewGroupParameter)
     {
         return this.ParameterNameGenerator.GenerateIdentifier("g");
     }
     else
     {
         return codeQuerySource.GroupParameterName;
     }
 }