Synchronization code

This commit is contained in:
sunkaixuan 2023-05-14 18:24:04 +08:00
parent 3a3a33913a
commit 7fe4e43fa5
4 changed files with 19 additions and 3 deletions

View File

@ -526,9 +526,16 @@ namespace SqlSugar
this.InsertBuilder.TableWithString = lockString;
return this;
}
public IInsertable<T> OffIdentity()
{
this.IsOffIdentity = true;
this.InsertBuilder.IsOffIdentity = true;
return this;
}
public IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) {
Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
this.IsOffIdentity = isOffIdentity;
this.InsertBuilder.IsOffIdentity = isOffIdentity;
if (this.InsertBuilder.LambdaExpressions == null)
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
this.InsertBuilder.IsNoInsertNull = ignoreNullColumn;

View File

@ -36,6 +36,7 @@ namespace SqlSugar
public virtual bool IsReturnPkList { get; set; }
public string AsName { get; set; }
public bool IsOffIdentity { get; set; }
#endregion
#region SqlTemplate

View File

@ -61,5 +61,6 @@ namespace SqlSugar
SplitInsertable<T> SplitTable(SplitType splitType);
void AddQueue();
IInsertable<T> MySqlIgnore();
IInsertable<T> OffIdentity();
}
}

View File

@ -22,10 +22,11 @@ namespace SqlSugar
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1;
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
var result = "";
if (isSingle)
{
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it =>base.GetDbColumn(it,Builder.SqlParameterKeyWord + it.DbColumnName)));
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
result= string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
}
else
{
@ -63,13 +64,19 @@ namespace SqlSugar
pageIndex++;
batchInsetrSql.Append("\r\n;\r\n");
}
var result = batchInsetrSql.ToString();
result = batchInsetrSql.ToString();
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
{
result += "select SCOPE_IDENTITY();";
}
return result;
}
if (this.IsOffIdentity)
{
var tableName = this.GetTableNameString;
result= $"SET IDENTITY_INSERT {tableName} ON;" + result.TrimEnd(';') + $";SET IDENTITY_INSERT {tableName} OFF"; ;
}
return result;
}
public override string FormatDateTimeOffset(object value)
{