mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Synchronization code
This commit is contained in:
parent
2a3761542a
commit
d433f80e7b
Src/Asp.Net/SqlSugar
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user