protected BulkCopyRowsCopied MultipleRowsCopy1 <T>( MultipleRowsHelper <T> helper, DataConnection dataConnection, BulkCopyOptions options, IEnumerable <T> source) { helper.StringBuilder .AppendFormat("INSERT INTO {0}", helper.TableName).AppendLine() .Append("("); foreach (var column in helper.Columns) { helper.StringBuilder .AppendLine() .Append("\t") .Append(helper.SqlBuilder.Convert(column.ColumnName, ConvertType.NameToQueryField)) .Append(","); } helper.StringBuilder.Length--; helper.StringBuilder .AppendLine() .Append(")"); helper.StringBuilder .AppendLine() .Append("VALUES"); helper.SetHeader(); foreach (var item in source) { helper.StringBuilder .AppendLine() .Append("("); helper.BuildColumns(item); helper.StringBuilder.Append("),"); helper.RowsCopied.RowsCopied++; helper.CurrentCount++; if (helper.CurrentCount >= helper.BatchSize || helper.Parameters.Count > 10000 || helper.StringBuilder.Length > 100000) { helper.StringBuilder.Length--; if (!helper.Execute()) { return(helper.RowsCopied); } } } if (helper.CurrentCount > 0) { helper.StringBuilder.Length--; helper.Execute(); } return(helper.RowsCopied); }
protected BulkCopyRowsCopied MultipleRowsCopy2( MultipleRowsHelper helper, IEnumerable source, string from) { helper.StringBuilder .AppendFormat("INSERT INTO {0}", helper.TableName).AppendLine() .Append("("); foreach (var column in helper.Columns) { helper.StringBuilder .AppendLine() .Append("\t"); helper.SqlBuilder.Convert(helper.StringBuilder, column.ColumnName, ConvertType.NameToQueryField); helper.StringBuilder.Append(","); } helper.StringBuilder.Length--; helper.StringBuilder .AppendLine() .Append(")"); helper.SetHeader(); foreach (var item in source) { helper.StringBuilder .AppendLine() .Append("SELECT "); helper.BuildColumns(item); helper.StringBuilder.Append(from); helper.StringBuilder.Append(" UNION ALL"); helper.RowsCopied.RowsCopied++; helper.CurrentCount++; if (helper.CurrentCount >= helper.BatchSize || helper.Parameters.Count > 10000 || helper.StringBuilder.Length > 100000) { helper.StringBuilder.Length -= " UNION ALL".Length; if (!helper.Execute()) { return(helper.RowsCopied); } } } if (helper.CurrentCount > 0) { helper.StringBuilder.Length -= " UNION ALL".Length; helper.Execute(); } return(helper.RowsCopied); }