public string GenerateMergeScript(InsertRowDesc row) { var tableName = row.ParsedTableName;// {0} var source = string.Join(", ", Array.ConvertAll(row.ColumnValuePairs, pair => string.Format("{0} AS [{1}]", pair.Value, pair.Key))); //{1} var match = row.HasPrimaryColumns ? string.Join(" AND ", Array.ConvertAll(row.PrimaryColumns, col => string.Format("(t.[{0}] = s.[{0}])", col))) : string.Join(" AND ", Array.ConvertAll(row.Columns, col => string.Format("((t.[{0}] IS NULL AND s.[{0}] IS NULL) OR t.[{0}] = s.[{0}])", col))); //{2} var update = row.HasPrimaryColumns ? string.Join(", ", Array.ConvertAll(row.SecondaryColumns.Value, col => string.Format("t.[{0}] = s.[{0}]", col))) : string.Join(", ", Array.ConvertAll(row.Columns, col => string.Format("t.[{0}] = s.[{0}]", col))); //{3} var insert = string.Join(", ", Array.ConvertAll(row.Columns, col => string.Format("[{0}]", col))); // {4} var values = string.Join(", ", Array.ConvertAll(row.Columns, col => string.Format("s.[{0}]", col))); //{5} var script = string.Format(ScriptTemplates.SingleMerge, tableName, source, match, update, insert, values); return script; }
public bool SchemaEquals(InsertRowDesc y) { var x = this; return y.Columns.All(yc => this.Columns.Count(xc => xc.Equals(yc)) > 0) && y.PrimaryColumns.All(yc => this.PrimaryColumns.Count(xc => xc.Equals(yc)) > 0) && y.ParsedTableName.Equals(x.ParsedTableName); }