Beispiel #1
0
        protected virtual Expression BuildExecuteCommand(CommandExpression command)
        {
            // parameterize query
            var expression = this.Parameterize(command);

            string commandText = this.linguist.Format(expression);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(expression);
            QueryCommand qc = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));

            Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray();

            ProjectionExpression projection = ProjectionFinder.FindProjection(expression);

            if (projection != null)
            {
                return(this.ExecuteProjection(projection, false, qc, values, isTopLevel: true));
            }

            var plan = Expression.Call(this.executor, nameof(QueryExecutor.ExecuteCommand), null,
                                       Expression.Constant(qc),
                                       Expression.NewArrayInit(typeof(object), values)
                                       );

            return(plan);
        }
Beispiel #2
0
        protected virtual Expression VisitCommand(CommandExpression command)
        {
            switch ((DbExpressionType)command.NodeType)
            {
            case DbExpressionType.Insert:
                return(this.VisitInsert((InsertCommand)command));

            case DbExpressionType.Update:
                return(this.VisitUpdate((UpdateCommand)command));

            case DbExpressionType.PartialUpdate:
                return(this.VisitPartialUpdate((PartialUpdateCommand)command));

            case DbExpressionType.Delete:
                return(this.VisitDelete((DeleteCommand)command));

            case DbExpressionType.If:
                return(this.VisitIf((IFCommand)command));

            case DbExpressionType.Block:
                return(this.VisitBlock((BlockCommand)command));

            case DbExpressionType.Declaration:
                return(this.VisitDeclaration((DeclarationCommand)command));

            default:
                return(this.VisitUnknown(command));
            }
        }
Beispiel #3
0
        protected virtual bool IsMultipleCommands(CommandExpression command)
        {
            if (command == null)
            {
                return(false);
            }
            switch ((DbExpressionType)command.NodeType)
            {
            case DbExpressionType.Insert:
            case DbExpressionType.Delete:
            case DbExpressionType.Update:
            case DbExpressionType.PartialUpdate:
                return(false);

            default:
                return(true);
            }
        }
Beispiel #4
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     if (this.linguist.Language.AllowsMultipleCommands || !IsMultipleCommands(command))
     {
         if (command.NodeType == (ExpressionType)DbExpressionType.PartialUpdate)
         {
             return(this.VisitPartialUpdate((PartialUpdateCommand)command));
         }
         else
         {
             return(this.BuildExecuteCommand(command));
         }
     }
     else
     {
         return(base.VisitCommand(command));
     }
 }
 protected override Expression VisitCommand(CommandExpression command)
 {
     this.isTopLevel = true;
     return(base.VisitCommand(command));
 }
Beispiel #6
0
 protected virtual Expression VisitCommand(CommandExpression command)
 {
     this.Write(this.FormatQuery(command));
     return(command);
 }