Update .net core project

This commit is contained in:
sunkaixuan
2022-07-26 22:30:11 +08:00
parent c27df74355
commit e44c35f3c6
3 changed files with 20 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ namespace SqlSugar
{
public partial class UpdateNavProvider<Root, T> where T : class, new() where Root : class, new()
{
public NavigateType? _NavigateType { get; set; }
private void UpdateOneToMany<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
{
List<TChild> children = new List<TChild>();
@@ -34,15 +34,17 @@ namespace SqlSugar
foreach (var child in childs)
{
thisFkColumn.PropertyInfo.SetValue(child, parentValue, null);
ids.Add(parentValue);
}
children.AddRange(childs);
}
ids.Add(parentValue);
}
this._Context.Deleteable<object>()
.AS(thisEntity.DbTableName)
.In(thisFkColumn.DbColumnName, ids.Distinct().ToList()).ExecuteCommand();
_NavigateType = NavigateType.OneToMany;
InsertDatas(children, thisPkColumn);
_NavigateType = null;
SetNewParent<TChild>(thisEntity, thisPkColumn);
}

View File

@@ -74,7 +74,14 @@ namespace SqlSugar
Check.ExceptionEasy(pkColumn == null && NavColumn == null, $"The entity is invalid", $"实体错误无法使用导航");
x.AsUpdateable.ExecuteCommand();
InitData(pkColumn, insertData);
this._ParentList = insertData.Union(updateData).Cast<object>().ToList();
if (_NavigateType == NavigateType.OneToMany)
{
this._ParentList = children.Cast<object>().ToList();
}
else
{
this._ParentList = insertData.Union(updateData).Cast<object>().ToList();
}
}
private void InitData<TChild>(EntityColumnInfo pkColumn, List<TChild> UpdateData) where TChild : class, new()

View File

@@ -68,6 +68,14 @@ namespace SqlSugar
queryable.Select($" {ToShortName(lastShortName)}.{queryable.SqlBuilder.GetTranslationColumnName(selectColumnInfo.DbColumnName)}");
var last = subInfos.First();
var FirstPkColumn = last.ThisEntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey);
if (last.Nav.Name2.HasValue())
{
var nav2 = last.ThisEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == last.Nav.Name2);
if (nav2 != null)
{
FirstPkColumn = nav2;
}
}
Check.ExceptionEasy(FirstPkColumn == null, $"{ last.ThisEntityInfo.EntityName} need PrimayKey", $"使用导航属性{ last.ThisEntityInfo.EntityName} 缺少主键");
var PkColumn = last.ParentEntityInfo.Columns.FirstOrDefault(it => it.PropertyName == last.Nav.Name);
Check.ExceptionEasy(PkColumn == null, $"{ last.ParentEntityInfo.EntityName} no found {last.Nav.Name}", $"{ last.ParentEntityInfo.EntityName} 不存在 {last.Nav.Name}");