db.UpdateNav difference logs that support primary tables

This commit is contained in:
sunkaixuan
2022-10-24 11:45:09 +08:00
parent 90ebb1cc0e
commit 4653f5016d
6 changed files with 31 additions and 7 deletions

View File

@@ -132,35 +132,40 @@ namespace SqlSugar
com(updateable);
updateable.ExecuteCommand();
}
else if (IsFirst && _RootOptions != null)
else if (IsFirst && _RootOptions != null)
{
var isInsert = _RootOptions.IsInsertRoot;
if (isInsert)
{
var newRoots=new List<Root>();
var newRoots = new List<Root>();
foreach (var item in _Roots)
{
var x = this._Context.Storageable(item).ToStorage();
if (x.InsertList.HasValue())
{
newRoots.Add( x.AsInsertable.ExecuteReturnEntity());
newRoots.Add(x.AsInsertable.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData).ExecuteReturnEntity());
}
else
else
{
x.AsUpdateable.ExecuteCommand();
x.AsUpdateable.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent, _RootOptions.DiffLogBizData).ExecuteCommand();
newRoots.Add(item);
}
}
_ParentList=_RootList=newRoots.Cast<object>().ToList();
_ParentList = _RootList = newRoots.Cast<object>().ToList();
}
else
{
this._Context.Updateable(_Roots)
.EnableDiffLogEventIF(_RootOptions.IsDiffLogEvent,_RootOptions.DiffLogBizData)
.UpdateColumns(_RootOptions.UpdateColumns)
.IgnoreColumns(_RootOptions.IgnoreColumns)
.ExecuteCommand();
}
}
else if (_RootOptions != null && _RootOptions?.IsDiffLogEvent == true)
{
this._Context.Updateable(_Roots).EnableDiffLogEvent(_RootOptions.DiffLogBizData).ExecuteCommand();
}
else
{
this._Context.Updateable(_Roots).ExecuteCommand();

View File

@@ -499,7 +499,14 @@ namespace SqlSugar
}
public IInsertable<T> EnableDiffLogEventIF(bool isDiffLogEvent, object diffLogBizData)
{
if (isDiffLogEvent)
{
return EnableDiffLogEvent(diffLogBizData);
}
return this;
}
public IInsertable<T> EnableDiffLogEvent(object businessData = null)
{
//Check.Exception(this.InsertObjs.HasValue() && this.InsertObjs.Count() > 1, "DiffLog does not support batch operations");

View File

@@ -198,6 +198,14 @@ namespace SqlSugar
this.Context.MappingTables.Add(entityName, tableName);
return this; ;
}
public IUpdateable<T> EnableDiffLogEventIF(bool isEnableDiffLog, object businessData = null)
{
if (isEnableDiffLog)
{
return EnableDiffLogEvent(businessData);
}
return this;
}
public IUpdateable<T> EnableDiffLogEvent(object businessData = null)
{
//Check.Exception(this.UpdateObjs.HasValue() && this.UpdateObjs.Count() > 1, "DiffLog does not support batch operations");

View File

@@ -27,6 +27,8 @@ namespace SqlSugar
public string IgnoreColumns { get; set; }
public string[] UpdateColumns { get; set; }
public bool IsInsertRoot { get; set; }
public bool IsDiffLogEvent { get; set; }
public object DiffLogBizData { get; set; }
}
public class UpdateNavOptions
{

View File

@@ -92,6 +92,7 @@ namespace SqlSugar
IUpdateable<T> IsEnableUpdateVersionValidation();
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
IUpdateable<T> EnableDiffLogEventIF(bool isEnableDiffLog,object businessData = null);
IUpdateable<T> ReSetValue(Action<T> setValueExpression);
IUpdateable<T> RemoveDataCache();
IUpdateable<T> RemoveDataCache(string likeString);

View File

@@ -40,6 +40,7 @@ namespace SqlSugar
IInsertable<T> CallEntityMethod(Expression<Action<T>> method);
IInsertable<T> EnableDiffLogEvent(object businessData = null);
IInsertable<T> EnableDiffLogEventIF(bool isDiffLogEvent, object businessData=null);
IInsertable<T> RemoveDataCache();
IInsertable<T> RemoveDataCache(string likeString);
KeyValuePair<string, List<SugarParameter>> ToSql();