mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Add BlueCopy
This commit is contained in:
@@ -228,6 +228,20 @@ namespace SqlSugar
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public SqlServerBlueCopy UseSqlServer()
|
||||
{
|
||||
PreToSql();
|
||||
var currentType = this.Context.CurrentConnectionConfig.DbType;
|
||||
Check.Exception(currentType != DbType.SqlServer, "UseSqlServer no support " + currentType);
|
||||
SqlServerBlueCopy result = new SqlServerBlueCopy();
|
||||
result.DbColumnInfoList =this.InsertBuilder.DbColumnInfoList.GroupBy(it => it.TableId).ToList();
|
||||
result.InsertBuilder = this.InsertBuilder;
|
||||
result.Builder = this.SqlBuilder;
|
||||
result.Context = this.Context;
|
||||
return result;
|
||||
}
|
||||
|
||||
public IInsertable<T> EnableDiffLogEvent(object businessData = null)
|
||||
{
|
||||
Check.Exception(this.InsertObjs.HasValue() && this.InsertObjs.Count() > 1, "DiffLog does not support batch operations");
|
||||
|
@@ -33,6 +33,7 @@ namespace SqlSugar
|
||||
IInsertable<T> EnableDiffLogEvent(object businessData = null);
|
||||
IInsertable<T> RemoveDataCache();
|
||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||
SqlServerBlueCopy UseSqlServer();
|
||||
void AddQueue();
|
||||
|
||||
#region Obsolete
|
||||
|
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SqlServerBlueCopy
|
||||
{
|
||||
internal List<IGrouping<int, DbColumnInfo>> DbColumnInfoList { get; set; }
|
||||
internal SqlSugarProvider Context { get; set; }
|
||||
internal ISqlBuilder Builder { get; set; }
|
||||
internal InsertBuilder InsertBuilder { get; set; }
|
||||
public int ExecuteBlueCopy()
|
||||
{
|
||||
if (DbColumnInfoList==null||DbColumnInfoList.Count == 0) return 0;
|
||||
int pmax = 2030;
|
||||
decimal count = DbColumnInfoList.Count;
|
||||
var columns = DbColumnInfoList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)).ToList();
|
||||
decimal columnCount = columns.Count();
|
||||
decimal pageSize = count / ((count * columnCount) / pmax);
|
||||
this.Context.Utilities.PageEach(DbColumnInfoList,Convert.ToInt32(pageSize), pageItems =>
|
||||
{
|
||||
StringBuilder batchInsetrSql = new StringBuilder();
|
||||
batchInsetrSql.AppendFormat(InsertBuilder.SqlTemplateBatch, InsertBuilder.GetTableNameString, string.Join(",", columns));
|
||||
int i = 0;
|
||||
foreach (var item in pageItems)
|
||||
{
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", item.ToList().Select(it => string.Format(InsertBuilder.SqlTemplateBatchSelect, AddParameter(i,it.DbColumnName,it.Value), Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
if (pageItems.Last() != item)
|
||||
{
|
||||
batchInsetrSql.Append(" UNION ALL");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
this.Context.Ado.ExecuteCommand(batchInsetrSql.ToString(),InsertBuilder.Parameters);
|
||||
InsertBuilder.Parameters = new List<SugarParameter>();
|
||||
});
|
||||
return count.ObjToInt();
|
||||
}
|
||||
|
||||
private object AddParameter(int i,string dbColumnName, object value)
|
||||
{
|
||||
var name =Builder.SqlParameterKeyWord+dbColumnName+i;
|
||||
InsertBuilder.Parameters.Add(new SugarParameter(name,value));
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
@@ -152,6 +152,7 @@
|
||||
<Compile Include="Realization\PostgreSQL\SqlBuilder\PostgreSQLInsertBuilder.cs" />
|
||||
<Compile Include="Realization\PostgreSQL\SqlBuilder\PostgreSQLQueryBuilder.cs" />
|
||||
<Compile Include="Realization\PostgreSQL\SqlBuilder\PostgreSQLUpdateBuilder.cs" />
|
||||
<Compile Include="Realization\SqlServer\SqlBuilder\SqlServerBlueCopy.cs" />
|
||||
<Compile Include="SqlSugarClient.cs" />
|
||||
<Compile Include="Utilities\CallContext.cs" />
|
||||
<Compile Include="Utilities\ReflectionExtensions.cs" />
|
||||
|
Reference in New Issue
Block a user