protected override void BuildOutputSubclause(SqlStatement statement, SqlInsertClause insertClause) { if (insertClause.WithIdentity) { var identityField = insertClause.Into !.GetIdentityField(); if (identityField != null && (identityField.Type !.Value.DataType == DataType.Guid || SqlServerConfiguration.GenerateScopeIdentity == false)) { StringBuilder .Append("OUTPUT [INSERTED]."); Convert(StringBuilder, identityField.PhysicalName, ConvertType.NameToQueryField); StringBuilder.AppendLine(); AppendIndent() .Append("INTO "); AppendOutputTableVariable(insertClause.Into) .AppendLine(); } } else { var output = statement.GetOutputClause(); BuildOutputSubclause(output); } }
protected override void BuildOutputSubclause(SqlStatement statement, SqlInsertClause insertClause) { if (insertClause.WithIdentity) { var identityField = insertClause.Into !.GetIdentityField(); if (identityField != null && (identityField.Type !.Value.DataType == DataType.Guid || SqlServerConfiguration.GenerateScopeIdentity == false)) { StringBuilder .Append("OUTPUT [INSERTED]."); Convert(StringBuilder, identityField.PhysicalName, ConvertType.NameToQueryField); StringBuilder.AppendLine(); AppendIndent() .Append("INTO "); AppendOutputTableVariable(insertClause.Into) .AppendLine(); } } else { var output = statement.GetOutputClause(); if (output != null && output.HasOutputItems) { AppendIndent() .AppendLine("OUTPUT"); if (output.InsertedTable != null) { output.InsertedTable.PhysicalName = "INSERTED"; } if (output.DeletedTable != null) { output.DeletedTable.PhysicalName = "DELETED"; } ++Indent; bool first = true; foreach (var oi in output.OutputItems) { if (!first) { StringBuilder.Append(',').AppendLine(); } first = false; AppendIndent(); BuildExpression(oi.Expression !); } if (output.OutputItems.Count > 0) { StringBuilder .AppendLine(); } --Indent; if (output.OutputQuery != null) { BuildColumns(output.OutputQuery); } if (output.OutputTable != null) { AppendIndent() .Append("INTO ") .Append(GetTablePhysicalName(output.OutputTable)) .AppendLine(); AppendIndent() .AppendLine("("); ++Indent; var firstColumn = true; foreach (var oi in output.OutputItems) { if (!firstColumn) { StringBuilder.Append(',').AppendLine(); } firstColumn = false; AppendIndent(); BuildExpression(oi.Column, false, true); } StringBuilder .AppendLine(); --Indent; AppendIndent() .AppendLine(")"); } } } }
protected override void BuildUpdateClause(SqlStatement statement, SelectQuery selectQuery, SqlUpdateClause updateClause) { base.BuildUpdateClause(statement, selectQuery, updateClause); BuildOutputSubclause(statement.GetOutputClause()); }