BulkCopy.OffIdentity

This commit is contained in:
sunkaixuan
2023-09-22 17:10:58 +08:00
parent 36f35f0d55
commit 868694733c
5 changed files with 28 additions and 3 deletions

View File

@@ -19,7 +19,9 @@ namespace SqlSugar
result.CharacterSet = this.CharacterSet; result.CharacterSet = this.CharacterSet;
return result; return result;
case DbType.SqlServer: case DbType.SqlServer:
return new SqlServerFastBuilder(); var result2= new SqlServerFastBuilder();
result2.DbFastestProperties.IsOffIdentity = this.IsOffIdentity;
return result2;
case DbType.Sqlite: case DbType.Sqlite:
return new SqliteFastBuilder(this.entityInfo); return new SqliteFastBuilder(this.entityInfo);
case DbType.Oracle: case DbType.Oracle:

View File

@@ -14,6 +14,7 @@ namespace SqlSugar
private string CacheKeyLike { get; set; } private string CacheKeyLike { get; set; }
private string CharacterSet { get; set; } private string CharacterSet { get; set; }
private bool IsDataAop { get; set; } private bool IsDataAop { get; set; }
private bool IsOffIdentity { get; set; }
public IFastest<T> SetCharacterSet(string CharacterSet) public IFastest<T> SetCharacterSet(string CharacterSet)
{ {
this.CharacterSet = CharacterSet; this.CharacterSet = CharacterSet;
@@ -44,6 +45,11 @@ namespace SqlSugar
this.Size = size; this.Size = size;
return this; return this;
} }
public IFastest<T> OffIdentity()
{
this.IsOffIdentity = true;
return this;
}
public SplitFastest<T> SplitTable() public SplitFastest<T> SplitTable()
{ {
SplitFastest<T> result = new SplitFastest<T>(); SplitFastest<T> result = new SplitFastest<T>();

View File

@@ -10,5 +10,6 @@ namespace SqlSugar
{ {
public bool HasOffsetTime { get; set; } public bool HasOffsetTime { get; set; }
public string[] WhereColumns { get; set; } public string[] WhereColumns { get; set; }
public bool IsOffIdentity { get; set; }
} }
} }

View File

@@ -12,6 +12,7 @@ namespace SqlSugar
IFastest<T> RemoveDataCache(string cacheKey); IFastest<T> RemoveDataCache(string cacheKey);
IFastest<T> AS(string tableName); IFastest<T> AS(string tableName);
IFastest<T> PageSize(int Size); IFastest<T> PageSize(int Size);
IFastest<T> OffIdentity();
IFastest<T> SetCharacterSet(string CharacterSet); IFastest<T> SetCharacterSet(string CharacterSet);
IFastest<T> EnableDataAop(); IFastest<T> EnableDataAop();
int BulkCopy(List<T> datas); int BulkCopy(List<T> datas);

View File

@@ -38,11 +38,26 @@ namespace SqlSugar
SqlBulkCopy copy; SqlBulkCopy copy;
if (this.Context.Ado.Transaction == null) if (this.Context.Ado.Transaction == null)
{ {
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection); if (this.DbFastestProperties?.IsOffIdentity == true)
{
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.KeepIdentity,null);
}
else
{
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection);
}
} }
else else
{ {
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction); if (this.DbFastestProperties?.IsOffIdentity == true)
{
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.KeepIdentity, (SqlTransaction)this.Context.Ado.Transaction);
}
else
{
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction);
}
} }
if (this.Context.Ado.Connection.State == ConnectionState.Closed) if (this.Context.Ado.Connection.State == ConnectionState.Closed)
{ {