protected virtual Expression BuildExecuteCommand(DbStatementExpression command) { // parameterize query var expression = this.Parameterize(command); string commandText = this.mapping.Language.Format(expression); ReadOnlyCollection <DbNamedValueExpression> namedValues = NamedValueGatherer.Gather(expression); QueryCommand qc = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.DbType)), null); Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray(); DbProjectionExpression projection = ProjectionFinder.FindProjection(expression); if (projection != null) { return(this.ExecuteProjection(projection, false, qc, values)); } Expression plan = Expression.Call(this.provider, "ExecuteCommand", null, Expression.Constant(qc), Expression.NewArrayInit(typeof(object), values) ); return(plan); }
protected virtual Expression VisitStatement(DbStatementExpression command) { switch ((DbExpressionType)command.NodeType) { case DbExpressionType.Insert: return(VisitInsert((DbInsertExpression)command)); case DbExpressionType.Update: return(VisitUpdate((DbUpdateExpression)command)); case DbExpressionType.Delete: return(VisitDelete((DbDeleteExpression)command)); case DbExpressionType.If: return(VisitIf((DbConditionalExpression)command)); case DbExpressionType.Block: return(VisitBlock((DbExpressionSet)command)); case DbExpressionType.Declaration: return(VisitDeclaration((DbDeclaration)command)); default: return(VisitUnknown(command)); } }
protected override Expression VisitStatement(DbStatementExpression command) { if (this.mapping.Language.AllowsMultipleCommands || !IsMultipleCommands(command)) { return(this.BuildExecuteCommand(command)); } else { return(base.VisitStatement(command)); } }
protected virtual bool IsMultipleCommands(DbStatementExpression command) { if (command == null) { return(false); } switch ((DbExpressionType)command.NodeType) { case DbExpressionType.Insert: case DbExpressionType.Delete: case DbExpressionType.Update: return(false); default: return(true); } }
protected virtual Expression VisitStatement(DbStatementExpression command) { switch ((DbExpressionType)command.NodeType) { case DbExpressionType.Insert: return VisitInsert((DbInsertExpression)command); case DbExpressionType.Update: return VisitUpdate((DbUpdateExpression)command); case DbExpressionType.Delete: return VisitDelete((DbDeleteExpression)command); case DbExpressionType.If: return VisitIf((DbConditionalExpression)command); case DbExpressionType.Block: return VisitBlock((DbExpressionSet)command); case DbExpressionType.Declaration: return VisitDeclaration((DbDeclaration)command); default: return VisitUnknown(command); } }
protected override Expression VisitStatement(DbStatementExpression command) { this.isTopLevel = true; return base.VisitStatement(command); }
protected override Expression VisitStatement(DbStatementExpression command) { this.isTopLevel = true; return(base.VisitStatement(command)); }