Browse Source

Update db.UpdateNav

SqlSugar5
sunkaixuan 2 years ago
parent
commit
2beae6ba6c
  1. 2
      Src/Asp.NetCore2/SqlSugar.MySqlConnectorCore/SqlSugar.MySqlConnectorCore.nuspec
  2. 20
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProvider.cs
  3. 4
      Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProviderHelper.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec

2
Src/Asp.NetCore2/SqlSugar.MySqlConnectorCore/SqlSugar.MySqlConnectorCore.nuspec

@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>SqlSugar.MySqlConnectorCore</id> <id>SqlSugar.MySqlConnectorCore</id>
<version>5.9.1</version> <version>5.9.5</version>
<authors>sunkaixuan</authors> <authors>sunkaixuan</authors>
<owners>Landa</owners> <owners>Landa</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>

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

@ -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();
}
}
}
} }
} }

4
Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavProviderHelper.cs

@ -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>();
} }

2
Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec

@ -2,7 +2,7 @@
<package > <package >
<metadata> <metadata>
<id>SqlSugarCore</id> <id>SqlSugarCore</id>
<version>5.0.9.6</version> <version>5.0.9.7-preview02</version>
<authors>sunkaixuan</authors> <authors>sunkaixuan</authors>
<owners>果糖大数据科技</owners> <owners>果糖大数据科技</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>

Loading…
Cancel
Save