Example #1
0
        protected override 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)), false);
            Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray();

            if (command is OInsertCommandExpression)
            {
                // insert will directly return a populated instance without the need for a BlockCommandExpression
                // to execute first an INSERT followed by a SELECT - so here we utilize the same Execute method
                // as a projection in order to map the returned values into an entity instance in a single call
                return ExecuteInsert((OInsertCommandExpression)command, qc, values);
            }
            else if (command is OUpdateCommandExpression)
            {
                // update will directly return a populated instance without the need for a BlockCommandExpression
                // to execute first an INSERT followed by a SELECT - so here we utilize the same Execute method
                // as a projection in order to map the returned values into an entity instance in a single call
                return ExecuteUpdate((OUpdateCommandExpression)command, qc, values);
            }
            else
            {
                ProjectionExpression projection = ProjectionFinder.FindProjection(expression);
                if (projection != null)
                {
                    return this.ExecuteProjection(projection, qc, values);
                }
            }

            Expression plan = Expression.Call(this.Executor, "ExecuteCommand", null,
                Expression.Constant(qc),
                Expression.NewArrayInit(typeof(object), values)
                );

            return plan;
        }
Example #2
0
 protected virtual Expression VisitCommand(CommandExpression command)
 {
     switch ((DbExpressionType)command.NodeType)
     {
         case DbExpressionType.Insert:
             return this.VisitInsert((InsertCommandExpression)command);
         case DbExpressionType.Update:
             return this.VisitUpdate((UpdateCommandExpression)command);
         case DbExpressionType.Delete:
             return this.VisitDelete((DeleteCommandExpression)command);
         case DbExpressionType.If:
             return this.VisitIf((IfCommandExpression)command);
         case DbExpressionType.Block:
             return this.VisitBlock((BlockCommandExpression)command);
         case DbExpressionType.Declaration:
             return this.VisitDeclaration((DeclarationCommand)command);
         default:
             return this.VisitUnknown(command);
     }
 }
 protected override Expression VisitCommand(CommandExpression command)
 {
     this.isTopLevel = true;
     return base.VisitCommand(command);
 }
Example #4
0
 protected override Expression VisitCommand(CommandExpression command)
 {
     return base.VisitCommand(command);
 }
Example #5
0
 protected override bool IsMultipleCommands(CommandExpression command)
 {
     return base.IsMultipleCommands(command);
 }
Example #6
0
 protected virtual Expression VisitCommand(CommandExpression command)
 {
     this.Write(this.FormatQuery(command));
     return command;
 }