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
@ -33,7 +33,9 @@ namespace SqlSugar
|
|||||||
resultConnector.CharacterSet = this.CharacterSet;
|
resultConnector.CharacterSet = this.CharacterSet;
|
||||||
return resultConnector;
|
return resultConnector;
|
||||||
case DbType.Dm:
|
case DbType.Dm:
|
||||||
return new DmFastBuilder();
|
var result3= new DmFastBuilder();
|
||||||
|
result3.DbFastestProperties.IsOffIdentity = this.IsOffIdentity;
|
||||||
|
return result3;
|
||||||
case DbType.ClickHouse:
|
case DbType.ClickHouse:
|
||||||
var resultConnectorClickHouse = InstanceFactory.CreateInstance<IFastBuilder>("SqlSugar.ClickHouse.ClickHouseFastBuilder");
|
var resultConnectorClickHouse = InstanceFactory.CreateInstance<IFastBuilder>("SqlSugar.ClickHouse.ClickHouseFastBuilder");
|
||||||
resultConnectorClickHouse.CharacterSet = this.CharacterSet;
|
resultConnectorClickHouse.CharacterSet = this.CharacterSet;
|
||||||
|
@ -17,7 +17,38 @@ namespace SqlSugar
|
|||||||
};
|
};
|
||||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
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();
|
DmBulkCopy bulkCopy = GetBulkCopyInstance();
|
||||||
bulkCopy.DestinationTableName = dt.TableName;
|
bulkCopy.DestinationTableName = dt.TableName;
|
||||||
try
|
try
|
||||||
@ -33,6 +64,7 @@ namespace SqlSugar
|
|||||||
CloseDb();
|
CloseDb();
|
||||||
return dt.Rows.Count;
|
return dt.Rows.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DmBulkCopy GetBulkCopyInstance()
|
public DmBulkCopy GetBulkCopyInstance()
|
||||||
{
|
{
|
||||||
DmBulkCopy copy;
|
DmBulkCopy copy;
|
||||||
|
Loading…
Reference in New Issue
Block a user