Ejemplo n.º 1
0
        public static CommandExpression Simplify(CommandExpression ce, bool removeSelectRowCount, AliasGenerator aliasGenerator)
        {
            if (removeSelectRowCount)
            {
                ce = (CommandExpression) new SelectRowRemover().Visit(ce);
            }

            return((CommandExpression) new CommandSimplifier(aliasGenerator).Visit(ce));
        }
Ejemplo n.º 2
0
 protected internal override Expression VisitCommandAggregate(CommandAggregateExpression cea)
 {
     for (int i = 0, n = cea.Commands.Count; i < n; i++)
     {
         CommandExpression command = cea.Commands[i];
         if (i > 0)
         {
             sb.Append(";");
             this.AppendNewLine(Indentation.Same);
         }
         this.Visit(command);
     }
     return(cea);
 }
Ejemplo n.º 3
0
        internal R Insert <R>(IQueryable query, LambdaExpression constructor, ITable table, Func <SqlPreCommandSimple, R> continuation, bool removeSelectRowCount = false)
        {
            AliasGenerator aliasGenerator = new AliasGenerator();

            SqlPreCommandSimple cr;

            using (HeavyProfiler.Log("LINQ"))
                using (var log = HeavyProfiler.LogNoStackTrace("Clean"))
                {
                    Expression cleaned = Clean(query.Expression, true, log) !;
                    var        binder  = new QueryBinder(aliasGenerator);
                    log.Switch("Bind");
                    CommandExpression insert           = binder.BindInsert(cleaned, constructor, table);
                    CommandExpression insertOprimized  = (CommandExpression)Optimize(insert, binder, aliasGenerator, log);
                    CommandExpression insertSimplified = CommandSimplifier.Simplify(insertOprimized, removeSelectRowCount, aliasGenerator);
                    log.Switch("TR");
                    cr = TranslatorBuilder.BuildCommandResult(insertSimplified);
                }
            return(continuation(cr));
        }
Ejemplo n.º 4
0
        internal R Update <R>(IUpdateable updateable, Func <SqlPreCommandSimple, R> continuation, bool removeSelectRowCount = false)
        {
            AliasGenerator aliasGenerator = new AliasGenerator();

            SqlPreCommandSimple cr;

            using (HeavyProfiler.Log("LINQ"))
                using (var log = HeavyProfiler.LogNoStackTrace("Clean"))
                {
                    Expression cleaned = Clean(updateable.Query.Expression, true, log) !;

                    var binder = new QueryBinder(aliasGenerator);
                    log.Switch("Bind");
                    CommandExpression update           = binder.BindUpdate(cleaned, updateable.PartSelector, updateable.SetterExpressions);
                    CommandExpression updateOptimized  = (CommandExpression)Optimize(update, binder, aliasGenerator, log);
                    CommandExpression updateSimplified = CommandSimplifier.Simplify(updateOptimized, removeSelectRowCount, aliasGenerator);
                    log.Switch("TR");
                    cr = TranslatorBuilder.BuildCommandResult(updateSimplified);
                }
            return(continuation(cr));
        }
Ejemplo n.º 5
0
        internal protected virtual R Delete <R>(IQueryable query, Func <SqlPreCommandSimple, R> continuation, bool removeSelectRowCount = false)
        {
            AliasGenerator aliasGenerator = new AliasGenerator();

            SqlPreCommandSimple cr;

            using (HeavyProfiler.Log("LINQ"))
                using (var log = HeavyProfiler.LogNoStackTrace("Clean"))
                {
                    Expression cleaned = Clean(query.Expression, true, log) !;

                    log.Switch("Bind");
                    var binder = new QueryBinder(aliasGenerator);
                    CommandExpression delete           = binder.BindDelete(cleaned);
                    CommandExpression deleteOptimized  = (CommandExpression)Optimize(delete, binder, aliasGenerator, log);
                    CommandExpression deleteSimplified = CommandSimplifier.Simplify(deleteOptimized, removeSelectRowCount, aliasGenerator);

                    cr = TranslatorBuilder.BuildCommandResult(deleteSimplified);
                }
            return(continuation(cr));
        }
Ejemplo n.º 6
0
 public static CommandExpression Simplify(CommandExpression ce, bool removeSelectRowCount, AliasGenerator aliasGenerator)
 {
     return((CommandExpression) new CommandSimplifier {
         removeSelectRowCount = removeSelectRowCount, aliasGenerator = aliasGenerator
     }.Visit(ce));
 }
 public static SqlPreCommandSimple BuildCommandResult(CommandExpression command)
 {
     return(QueryFormatter.Format(command));
 }