Browse Source

Update i gnoring NULL columns supports batch

pull/31/head
sunkaixuan 2 years ago
parent
commit
76c7a2f757
  1. 32
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs
  2. 5
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

32
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs

@ -11,6 +11,11 @@ namespace SqlSugar
{
public partial class UpdateableProvider<T> : IUpdateable<T> where T : class, new()
{
private bool IsUpdateNullByList()
{
return this.UpdateObjs.Count() > 1 && (this.UpdateBuilder.IsNoUpdateNull || this.UpdateBuilder.IsNoUpdateDefaultValue);
}
private int DatasTrackingExecommand()
{
var trakRows = 0;
@ -97,22 +102,25 @@ namespace SqlSugar
}
private void AppendTracking(T item, IUpdateable<T> newUpdateable)
{
var trackingData = this.Context.TempItems.FirstOrDefault(it => it.Key.StartsWith("Tracking_" + item.GetHashCode()));
var diffColumns = FastCopy.GetDiff(item, (T)trackingData.Value);
if (diffColumns.Count > 0)
if (IsTrakingData() || IsTrakingDatas())
{
var pks = EntityInfo.Columns
.Where(it => it.IsPrimarykey).Select(it => it.PropertyName).ToList();
diffColumns = diffColumns.Where(it => !pks.Contains(it)).ToList();
var trackingData = this.Context.TempItems.FirstOrDefault(it => it.Key.StartsWith("Tracking_" + item.GetHashCode()));
var diffColumns = FastCopy.GetDiff(item, (T)trackingData.Value);
if (diffColumns.Count > 0)
{
newUpdateable.UpdateColumns(diffColumns.ToArray());
var pks = EntityInfo.Columns
.Where(it => it.IsPrimarykey).Select(it => it.PropertyName).ToList();
diffColumns = diffColumns.Where(it => !pks.Contains(it)).ToList();
if (diffColumns.Count > 0)
{
newUpdateable.UpdateColumns(diffColumns.ToArray());
}
}
else
{
(newUpdateable as UpdateableProvider<T>).UpdateObjs = new T[] { null };
newUpdateable.UpdateBuilder.DbColumnInfoList = new List<DbColumnInfo>();
}
}
else
{
(newUpdateable as UpdateableProvider<T>).UpdateObjs = new T[] { null };
newUpdateable.UpdateBuilder.DbColumnInfoList = new List<DbColumnInfo>();
}
}
private void AppendSets()

5
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -80,7 +80,7 @@ namespace SqlSugar
public virtual int ExecuteCommand()
{
if (this.IsTrakingDatas())
if (this.IsTrakingDatas() || IsUpdateNullByList())
{
int trakRows = DatasTrackingExecommand();
return trakRows;
@ -95,6 +95,7 @@ namespace SqlSugar
return result;
}
public bool ExecuteCommandHasChange()
{
return this.ExecuteCommand() > 0;
@ -277,7 +278,7 @@ namespace SqlSugar
public IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false, bool ignoreAllDefaultValue = false)
{
Check.Exception(this.UpdateObjs.Count() > 1 && ignoreAllNullColumns, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
//Check.Exception(this.UpdateObjs.Count() > 1 && ignoreAllNullColumns, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作"));
UpdateBuilder.IsOffIdentity = isOffIdentity;
if (this.UpdateBuilder.LambdaExpressions == null)
this.UpdateBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig);

Loading…
Cancel
Save