diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavTask.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavTask.cs index 1a97e5043..1310bf779 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavTask.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavTask.cs @@ -66,8 +66,9 @@ namespace SqlSugar result.Context = UpdateNavProvider._Context; var entityInfo = result.Context.EntityMaintenance.GetEntityInfo(); Type properyItemType; - Expression exp =UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType); - var method = this.GetType().GetMyMethod("Include", 2) + 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; diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateNavMethodInfo.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateNavMethodInfo.cs index 096a6dbce..15f4b9e8f 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateNavMethodInfo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateNavMethodInfo.cs @@ -15,24 +15,26 @@ namespace SqlSugar public UpdateNavMethodInfo IncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null) { var type = MethodInfos.GetType().GetGenericArguments()[0]; - var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); + var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); Type properyItemType; - Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType); - var method = this.GetType().GetMyMethod("Include", 2) + 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, new object[] { exp, updateNavOptions }); + var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions }); this.MethodInfos = obj; return this; } - public UpdateNavMethodInfo ThenIncludeByNameString(string IncludeByNameString, UpdateNavOptions updateNavOptions = null) + public UpdateNavMethodInfo ThenIncludeByNameString(string navMemberName, UpdateNavOptions updateNavOptions = null) { var type = MethodInfos.GetType().GetGenericArguments()[0]; var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type); Type properyItemType; - Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType); - var method = this.GetType().GetMyMethod("ThenInclude", 2) + 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, new object[] { exp, updateNavOptions }); + var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions }); this.MethodInfos = obj; return this; } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs index ee7606cd8..3a855fb28 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/CommonExtensions.cs @@ -32,6 +32,14 @@ namespace SqlSugar it.GetParameters().Length == argCount&& it.GetParameters().First().ParameterType==parameterType); } + public static MethodInfo GetMyMethod(this Type type, string name, int argCount, bool isList) + { + var methods= type.GetMethods().Where(it => it.Name == name).Where(it => + it.GetParameters().Length == argCount&& + it.GetParameters()[0].ToString().Contains("List`") == isList).ToList(); + return methods.First(); + } + public static MethodInfo GetMyMethod(this Type type, string name, int argCount, Type parameterType,Type parameterType2) { return type.GetMethods().Where(it=>it.Name == name).FirstOrDefault(it => diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index bcfe06427..bf37a70eb 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -18,7 +18,7 @@ namespace SqlSugar { public class UtilMethods { - internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType) + internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType,out bool isList) { var navInfo = entityInfo.Columns.Where(it => it.Navigat != null && it.PropertyName.EqualCase(navMemberName)).FirstOrDefault(); var properyType = navInfo.PropertyInfo.PropertyType; @@ -26,6 +26,11 @@ namespace SqlSugar if (properyType.FullName.IsCollectionsList()) { properyItemType = properyType.GetGenericArguments()[0]; + isList = true; + } + else + { + isList = false; } return ExpressionBuilderHelper.CreateExpressionSelectField(entityInfo.Type, navInfo.PropertyName, properyType); }