Synchronization code

This commit is contained in:
sunkaixuan 2023-11-04 00:38:18 +08:00
parent 2a3761542a
commit d433f80e7b
2 changed files with 35 additions and 1 deletions
Src/Asp.Net/SqlSugar
Abstract/FastestProvider
Realization/Dm/SqlBuilder

View File

@ -33,7 +33,9 @@ namespace SqlSugar
resultConnector.CharacterSet = this.CharacterSet;
return resultConnector;
case DbType.Dm:
return new DmFastBuilder();
var result3= new DmFastBuilder();
result3.DbFastestProperties.IsOffIdentity = this.IsOffIdentity;
return result3;
case DbType.ClickHouse:
var resultConnectorClickHouse = InstanceFactory.CreateInstance<IFastBuilder>("SqlSugar.ClickHouse.ClickHouseFastBuilder");
resultConnectorClickHouse.CharacterSet = this.CharacterSet;

View File

@ -17,7 +17,38 @@ namespace SqlSugar
};
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
{
if (DbFastestProperties?.IsOffIdentity == true)
{
var isNoTran = this.Context.Ado.IsNoTran()&&this.Context.CurrentConnectionConfig.IsAutoCloseConnection;
try
{
if(isNoTran)
this.Context.Ado.BeginTran();
this.Context.Ado.ExecuteCommand($"SET IDENTITY_INSERT {dt.TableName} ON");
var result=await _Execute(dt);
this.Context.Ado.ExecuteCommand($"SET IDENTITY_INSERT {dt.TableName} OFF");
if (isNoTran)
this.Context.Ado.CommitTran();
return result;
}
catch (Exception)
{
if (isNoTran)
this.Context.Ado.CommitTran();
throw;
}
}
else
{
return await _Execute(dt);
}
}
private async Task<int> _Execute(DataTable dt)
{
DmBulkCopy bulkCopy = GetBulkCopyInstance();
bulkCopy.DestinationTableName = dt.TableName;
try
@ -33,6 +64,7 @@ namespace SqlSugar
CloseDb();
return dt.Rows.Count;
}
public DmBulkCopy GetBulkCopyInstance()
{
DmBulkCopy copy;