diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs index 1ed5d4be6..2e18b8f57 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs @@ -43,6 +43,22 @@ namespace SqlSugar } return methodInfo; } + public InsertNavMethodInfo IncludesAllFirstLayer(InsertNavOptions insertNavOptions,params string[] ignoreColumns) + { + if (ignoreColumns == null) + { + ignoreColumns = new string[] { }; + } + this.Context = insertNavProvider._Context; + var navColumns = this.Context.EntityMaintenance.GetEntityInfo().Columns.Where(it => !ignoreColumns.Contains(it.PropertyName) || !ignoreColumns.Any(z => z.EqualCase(it.DbColumnName))).Where(it => it.Navigat != null).ToList(); + var updateNavs = this; + InsertNavMethodInfo methodInfo = updateNavs.IncludeByNameString(navColumns[0].PropertyName); + foreach (var item in navColumns.Skip(1)) + { + methodInfo = methodInfo.IncludeByNameString(item.PropertyName, insertNavOptions); + } + return methodInfo; + } public InsertNavTask Include(Expression> expression) where TChild : class, new() { Check.ExceptionEasy(typeof(TChild).FullName.Contains("System.Collections.Generic.List`"), " need where T: class, new() ", "需要Class,new()约束,并且类属性中不能有required修饰符"); diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertNavMethodInfo.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertNavMethodInfo.cs index 8e25c886d..12ad41e69 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertNavMethodInfo.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertNavMethodInfo.cs @@ -11,7 +11,7 @@ namespace SqlSugar internal object MethodInfos { get; set; } internal SqlSugarProvider Context { get; set; } - public InsertNavMethodInfo IncludeByNameString(string navMemberName, InsertNavRootOptions updateNavOptions = null) + public InsertNavMethodInfo IncludeByNameString(string navMemberName, InsertNavOptions insertNavOptions = null) { var type = MethodInfos.GetType().GetGenericArguments()[0]; var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); @@ -20,11 +20,11 @@ namespace SqlSugar Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList); var method = this.MethodInfos.GetType().GetMyMethod("Include", 2, isList) .MakeGenericMethod(properyItemType); - var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions }); + var obj = method.Invoke(this.MethodInfos, new object[] { exp, insertNavOptions }); this.MethodInfos = obj; return this; } - public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, InsertNavRootOptions updateNavOptions = null) + public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, InsertNavOptions insertNavOptions = null) { var type = MethodInfos.GetType().GetGenericArguments()[1]; var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); @@ -33,7 +33,7 @@ namespace SqlSugar Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList); var method = this.MethodInfos.GetType().GetMyMethod("ThenInclude", 2, isList) .MakeGenericMethod(properyItemType); - var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions }); + var obj = method.Invoke(this.MethodInfos, new object[] { exp, insertNavOptions }); this.MethodInfos = obj; return this; }