Synchronization code

This commit is contained in:
sunkaixuan 2022-07-18 18:15:12 +08:00
parent 47637e9cc2
commit 3b5e5f3f34
2 changed files with 19 additions and 5 deletions

View File

@ -53,6 +53,7 @@ namespace SqlSugar
private UpdateNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, TChild>> expression) where TChild : class, new() private UpdateNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, TChild>> expression) where TChild : class, new()
{ {
var isRoot = _RootList == null;
InitParentList(); InitParentList();
var name = ExpressionTool.GetMemberName(expression); var name = ExpressionTool.GetMemberName(expression);
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name); var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
@ -60,6 +61,7 @@ namespace SqlSugar
{ {
Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性"); Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性");
} }
UpdateRoot(isRoot, nav);
if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne) if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne)
{ {
UpdateOneToOne<TChild>(name, nav); UpdateOneToOne<TChild>(name, nav);
@ -74,9 +76,9 @@ namespace SqlSugar
} }
return GetResult<TChild>(); return GetResult<TChild>();
} }
private UpdateNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new() private UpdateNavProvider<Root, TChild> _ThenInclude<TChild>(Expression<Func<T, List<TChild>>> expression) where TChild : class, new()
{ {
var isRoot = _RootList == null;
InitParentList(); InitParentList();
var name = ExpressionTool.GetMemberName(expression); var name = ExpressionTool.GetMemberName(expression);
var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name); var nav = this._ParentEntity.Columns.FirstOrDefault(x => x.PropertyName == name);
@ -84,6 +86,7 @@ namespace SqlSugar
{ {
Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性"); Check.ExceptionEasy($"{name} no navigate attribute", $"{this._ParentEntity.EntityName}的属性{name}没有导航属性");
} }
UpdateRoot(isRoot, nav);
if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne) if (nav.Navigat.NavigatType == NavigateType.OneToOne || nav.Navigat.NavigatType == NavigateType.ManyToOne)
{ {
UpdateOneToOne<TChild>(name, nav); UpdateOneToOne<TChild>(name, nav);
@ -98,5 +101,20 @@ namespace SqlSugar
} }
return GetResult<TChild>(); return GetResult<TChild>();
} }
private void UpdateRoot(bool isRoot, EntityColumnInfo nav)
{
if (isRoot && nav.Navigat.NavigatType != NavigateType.ManyToMany)
{
this._Context.Updateable(_Roots).ExecuteCommand();
}
else
{
if (_Options != null && _Options.ManyToManyIsUpdateA)
{
this._Context.Updateable(_Roots).ExecuteCommand();
}
}
}
} }
} }

View File

@ -18,10 +18,6 @@ namespace SqlSugar
{ {
if (_RootList == null) if (_RootList == null)
{ {
if (_Options != null && _Options.ManyToManyIsUpdateA)
{
this._Context.Updateable(_Roots).ExecuteCommand();
}
_RootList = _ParentList = _Roots.Cast<object>().ToList(); _RootList = _ParentList = _Roots.Cast<object>().ToList();
_ParentEntity = this._Context.EntityMaintenance.GetEntityInfo<Root>(); _ParentEntity = this._Context.EntityMaintenance.GetEntityInfo<Root>();
} }