mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Synchronization code
This commit is contained in:
parent
3a3a33913a
commit
7fe4e43fa5
@ -526,9 +526,16 @@ namespace SqlSugar
|
|||||||
this.InsertBuilder.TableWithString = lockString;
|
this.InsertBuilder.TableWithString = lockString;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public IInsertable<T> OffIdentity()
|
||||||
|
{
|
||||||
|
this.IsOffIdentity = true;
|
||||||
|
this.InsertBuilder.IsOffIdentity = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
public IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) {
|
public IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) {
|
||||||
Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
|
Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
|
||||||
this.IsOffIdentity = isOffIdentity;
|
this.IsOffIdentity = isOffIdentity;
|
||||||
|
this.InsertBuilder.IsOffIdentity = isOffIdentity;
|
||||||
if (this.InsertBuilder.LambdaExpressions == null)
|
if (this.InsertBuilder.LambdaExpressions == null)
|
||||||
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);
|
||||||
this.InsertBuilder.IsNoInsertNull = ignoreNullColumn;
|
this.InsertBuilder.IsNoInsertNull = ignoreNullColumn;
|
||||||
|
@ -36,6 +36,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public virtual bool IsReturnPkList { get; set; }
|
public virtual bool IsReturnPkList { get; set; }
|
||||||
public string AsName { get; set; }
|
public string AsName { get; set; }
|
||||||
|
public bool IsOffIdentity { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SqlTemplate
|
#region SqlTemplate
|
||||||
|
@ -61,5 +61,6 @@ namespace SqlSugar
|
|||||||
SplitInsertable<T> SplitTable(SplitType splitType);
|
SplitInsertable<T> SplitTable(SplitType splitType);
|
||||||
void AddQueue();
|
void AddQueue();
|
||||||
IInsertable<T> MySqlIgnore();
|
IInsertable<T> MySqlIgnore();
|
||||||
|
IInsertable<T> OffIdentity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ namespace SqlSugar
|
|||||||
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
|
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
|
||||||
var isSingle = groupList.Count() == 1;
|
var isSingle = groupList.Count() == 1;
|
||||||
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
|
||||||
|
var result = "";
|
||||||
if (isSingle)
|
if (isSingle)
|
||||||
{
|
{
|
||||||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it =>base.GetDbColumn(it,Builder.SqlParameterKeyWord + it.DbColumnName)));
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -63,13 +64,19 @@ namespace SqlSugar
|
|||||||
pageIndex++;
|
pageIndex++;
|
||||||
batchInsetrSql.Append("\r\n;\r\n");
|
batchInsetrSql.Append("\r\n;\r\n");
|
||||||
}
|
}
|
||||||
var result = batchInsetrSql.ToString();
|
result = batchInsetrSql.ToString();
|
||||||
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||||
{
|
{
|
||||||
result += "select SCOPE_IDENTITY();";
|
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)
|
public override string FormatDateTimeOffset(object value)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user