Synchronization code

This commit is contained in:
sunkaixuan 2023-12-09 15:53:09 +08:00
parent 039b716a91
commit 882bdfb290
3 changed files with 22 additions and 3 deletions

View File

@ -16,6 +16,7 @@ namespace SqlSugar
public bool IsEnableDiffLogEvent { get; internal set; }
public DiffLogModel DiffModel { get; internal set; }
public bool IsOffIdentity { get; internal set; }
public bool IsInsertColumnsNull { get; internal set; }
public int ExecuteCommand()
{
@ -34,7 +35,7 @@ namespace SqlSugar
}
this.Context.Utilities.PageEach(DataList, PageSize, pageItem =>
{
result += this.Context.Insertable(pageItem).AS(TableName).OffIdentity(IsOffIdentity).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).InsertColumns(InsertColumns.ToArray()).ExecuteCommand();
result += this.Context.Insertable(pageItem).AS(TableName).IgnoreColumnsNull(this.IsInsertColumnsNull).OffIdentity(IsOffIdentity).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).InsertColumns(InsertColumns.ToArray()).ExecuteCommand();
});
if (isNoTran)
{
@ -68,7 +69,7 @@ namespace SqlSugar
}
await this.Context.Utilities.PageEachAsync(DataList, PageSize, async pageItem =>
{
result +=await this.Context.Insertable(pageItem).AS(TableName).OffIdentity(IsOffIdentity).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).InsertColumns(InsertColumns.ToArray()).ExecuteCommandAsync();
result +=await this.Context.Insertable(pageItem).AS(TableName).IgnoreColumnsNull(this.IsInsertColumnsNull).OffIdentity(IsOffIdentity).EnableDiffLogEventIF(IsEnableDiffLogEvent, DiffModel).InsertColumns(InsertColumns.ToArray()).ExecuteCommandAsync();
});
if (isNoTran)
{
@ -154,5 +155,12 @@ namespace SqlSugar
}
return result;
}
public InsertablePage<T> IgnoreColumnsNull(bool isIgnoreNull = true)
{
this.PageSize = 1;
this.IsInsertColumnsNull = isIgnoreNull;
return this;
}
}
}

View File

@ -522,6 +522,16 @@ namespace SqlSugar
return this;
}
public IInsertable<T> IgnoreColumnsNull(bool isIgnoreNull = true)
{
if (isIgnoreNull)
{
Check.Exception(this.InsertObjs.Count() > 1 , ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert, use .PageSize(1).IgnoreColumnsNull().ExecuteCommand()", "ignoreNullColumn 不支持批量操作,你可以用PageSzie(1).IgnoreColumnsNull().ExecuteCommand()"));
this.InsertBuilder.IsNoInsertNull = true;
}
return this;
}
public IInsertable<T> MySqlIgnore()
{
this.InsertBuilder.MySqlIgnore = true;
@ -567,7 +577,7 @@ namespace SqlSugar
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 不支持批量操作"));
Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert, use .PageSize(1).IgnoreColumnsNull().ExecuteCommand()", "ignoreNullColumn 不支持批量操作, 你可以使用 .PageSize(1).IgnoreColumnsNull().ExecuteCommand()"));
this.IsOffIdentity = isOffIdentity;
this.InsertBuilder.IsOffIdentity = isOffIdentity;
if (this.InsertBuilder.LambdaExpressions == null)

View File

@ -43,6 +43,7 @@ namespace SqlSugar
IInsertable<T> IgnoreColumns(Expression<Func<T, object>> columns);
IInsertable<T> IgnoreColumns(params string[]columns);
IInsertable<T> IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false);
IInsertable<T> IgnoreColumnsNull(bool isIgnoreNull = true);
ISubInsertable<T> AddSubList(Expression<Func<T, object>> subForeignKey);
ISubInsertable<T> AddSubList(Expression<Func<T, SubInsertTree>> tree);