private void BuildInsertAction(MergeSpecification specification) { var action = new InsertMergeAction(); var insertSource = action.Source = new ValuesInsertSource(); var row = new RowValue(); foreach (var column in _merge.Table.Columns) { var colRef = new ColumnReferenceExpression(); colRef.ColumnType = ColumnType.Regular; colRef.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(column.Name.GetName()); action.Columns.Add(colRef); colRef = new ColumnReferenceExpression(); colRef.ColumnType = ColumnType.Regular; colRef.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, column.Name.GetName()); row.ColumnValues.Add(colRef); } insertSource.RowValues.Add(row); specification.ActionClauses.Add(new MergeActionClause { Action = action, Condition = MergeCondition.NotMatchedByTarget }); }
private ScalarExpression GetColumnOrCastColumn(ColumnDescriptor column, string tableName) { var columnReference = new ColumnReferenceExpression(); columnReference.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(tableName, column.Name.GetName()); if (column.UnderlyingType == "xml") { var cast = new CastCall(); var type = new SqlDataTypeReference(); type.SqlDataTypeOption = SqlDataTypeOption.NVarChar; type.Parameters.Add(new MaxLiteral()); cast.DataType = type; cast.Parameter = columnReference; return(cast); } return(columnReference); }
private UpdateMergeAction CreateUpdateSetActions(MergeActionClause clause) { var action = (clause.Action = new UpdateMergeAction()) as UpdateMergeAction; foreach (var col in _merge.Table.Columns) { var setClause = new AssignmentSetClause(); setClause.AssignmentKind = AssignmentKind.Equals; var identifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.TargetName, col.Name.GetName()); setClause.Column = new ColumnReferenceExpression(); setClause.Column.MultiPartIdentifier = identifier; var newValue = (setClause.NewValue = new ColumnReferenceExpression()) as ColumnReferenceExpression; newValue.MultiPartIdentifier = MultiPartIdentifierBuilder.Get(MergeIdentifierStrings.SourceName, col.Name.GetName()); action.SetClauses.Add(setClause); } return(action); }