Browse Source

Update db.UpdateNav

SqlSugar5
sunkaixuan 2 years ago
parent
commit
5b5221e7b3
  1. 20
      Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs
  2. 14
      Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProviderHelper.cs
  3. 3
      Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs

20
Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs

@ -105,16 +105,32 @@ namespace SqlSugar
{
if (isRoot && nav.Navigat.NavigatType != NavigateType.ManyToMany)
{
this._Context.Updateable(_Roots).ExecuteCommand();
UpdateRoot();
}
else
{
if (_Options != null && _Options.ManyToManyIsUpdateA)
{
this._Context.Updateable(_Roots).ExecuteCommand();
UpdateRoot();
}
}
}
private void UpdateRoot()
{
if (_Options != null && _Options.RootFunc != null)
{
var updateable = this._Context.Updateable(_Roots);
var exp= _Options.RootFunc as Expression<Action<IUpdateable<Root>>>;
Check.ExceptionEasy(exp == null, "UpdateOptions.RootFunc is error", "UpdateOptions.RootFunc");
var com= exp.Compile();
com(updateable);
updateable.ExecuteCommand();
}
else
{
this._Context.Updateable(_Roots).ExecuteCommand();
}
}
}
}

14
Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProviderHelper.cs

@ -72,7 +72,19 @@ namespace SqlSugar
var insertData = x.InsertList.Select(it => it.Item).ToList();
var updateData = x.UpdateList.Select(it => it.Item).ToList();
Check.ExceptionEasy(pkColumn == null && NavColumn == null, $"The entity is invalid", $"实体错误无法使用导航");
x.AsUpdateable.ExecuteCommand();
if (_Options != null && _Options.CurrentFunc != null)
{
var updateable = x.AsUpdateable;
var exp = _Options.CurrentFunc as Expression<Action<IUpdateable<TChild>>>;
Check.ExceptionEasy(exp == null, "UpdateOptions.CurrentFunc is error", "UpdateOptions.CurrentFunc参数设置错误");
var com = exp.Compile();
com(updateable);
updateable.ExecuteCommand();
}
else
{
x.AsUpdateable.ExecuteCommand();
}
InitData(pkColumn, insertData);
if (_NavigateType == NavigateType.OneToMany)
{

3
Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
@ -16,6 +17,8 @@ namespace SqlSugar
public bool ManyToManyIsUpdateA { get; set; }
public bool ManyToManyIsUpdateB { get; set; }
public bool OneToManyDeleteAll { get; set; }
public Expression RootFunc { get; set; }
public Expression CurrentFunc { get; set; }
}
public class InsertNavOptions

Loading…
Cancel
Save