diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs index 3a5473773..696497d62 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavTask.cs @@ -13,7 +13,20 @@ namespace SqlSugar internal SqlSugarProvider Context { get; set; } internal InsertNavProvider insertNavProvider { get; set; } internal NavContext NavContext { get; set; } - + public InsertNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null) + { + InsertNavMethodInfo result = new InsertNavMethodInfo(); + result.Context = insertNavProvider._Context; + var entityInfo = result.Context.EntityMaintenance.GetEntityInfo(); + Type properyItemType; + bool isList; + Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList); + var method = this.GetType().GetMyMethod("Include", 2, isList) + .MakeGenericMethod(properyItemType); + var obj = method.Invoke(this, new object[] { exp, updateNavOptions }); + result.MethodInfos = obj; + return result; + } 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 new file mode 100644 index 000000000..2622b2ed5 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertNavMethodInfo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace SqlSugar +{ + public class InsertNavMethodInfo + { + internal object MethodInfos { get; set; } + internal SqlSugarProvider Context { get; set; } + + public InsertNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null) + { + var type = MethodInfos.GetType().GetGenericArguments()[0]; + var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); + Type properyItemType; + bool isList; + 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 }); + this.MethodInfos = obj; + return this; + } + public InsertNavMethodInfo ThenIncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null) + { + var type = MethodInfos.GetType().GetGenericArguments()[0]; + var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); + Type properyItemType; + bool isList; + 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 }); + this.MethodInfos = obj; + return this; + } + public async Task ExecuteCommandAsync() + { + if (Context == null) return false; + var result = MethodInfos.GetType().GetMethod("ExecuteCommandAsync").Invoke(MethodInfos, new object[] { }); + return await (Task)result; + } + public bool ExecuteCommand() + { + if (Context == null) return false; + var result = MethodInfos.GetType().GetMethod("ExecuteCommand").Invoke(MethodInfos, new object[] { }); + return (bool)result; + } + } +}