private static void Format(this MergeMatchResult result, TypeMeta typeMeta, Action <MergeActionOptions> optionsAction, StringBuilder sb) { if (optionsAction == null) { return; } var options = new MergeActionOptions(); optionsAction(options); if (options.Action == MergeAction.None) { return; } if (options.Columns == null) { options.Columns = typeMeta.PropertiesExceptKeyAndComputed; } switch (result) { case MergeMatchResult.Matched: sb.Append("WHEN MATCHED"); break; case MergeMatchResult.NotMatchedBySource: sb.AppendLine("WHEN NOT MATCHED BY SOURCE"); break; case MergeMatchResult.NotMatchedByTarget: sb.AppendLine("WHEN NOT MATCHED BY TARGET"); break; } if (!string.IsNullOrEmpty(options.Condition)) { sb.AppendFormat(" AND ({0})", options.Condition); } sb.AppendLine(" THEN"); MergeActionFormat(options, sb); }
private static void MergeActionFormat(MergeActionOptions options, StringBuilder sb) { switch (options.Action) { case MergeAction.Insert: sb.AppendFormat("INSERT({0})", options.Columns.ColumnList()); sb.AppendLine(); sb.AppendFormat("VALUES({0})", options.Columns.ColumnList("Source")); sb.AppendLine(); break; case MergeAction.Update: sb.AppendLine("UPDATE SET"); sb.AppendLine(options.Columns.ColumnListEquals(", ", leftPrefix: string.Empty)); break; case MergeAction.Delete: sb.AppendLine("DELETE"); break; } }
public static void Format <T>(this MergeMatchResult result, TypeMeta typeMeta, Action <MergeActionOptions <T> > optionsAction, StringBuilder sb) { if (optionsAction == null) { return; } var options = new MergeActionOptions <T>(); optionsAction(options); if (options.Action == MergeAction.None) { return; } switch (result) { case MergeMatchResult.Matched: sb.AppendLine("WHEN MATCHED"); break; case MergeMatchResult.NotMatchedBySource: sb.AppendLine("WHEN NOT MATCHED BY SOURCE"); break; case MergeMatchResult.NotMatchedByTarget: sb.AppendLine("WHEN NOT MATCHED BY TARGET"); break; } if (!string.IsNullOrEmpty(options.Condition)) { sb.AppendFormat(" AND ({0})", options.Condition); } sb.AppendLine(" THEN"); options.Format(sb); }