From efefc2aebccbac941a69e26991b373c1cea8eb46 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 19 Jun 2023 08:08:36 +0800 Subject: [PATCH] queryable.IncludesByNameString(+5) --- .../Abstract/QueryableProvider/Includes.cs | 49 ++++++++++++++++++- .../QueryableProvider/IncludesHelper.cs | 38 ++++++++++++++ .../SqlSugar/Interface/IIncludes.cs | 2 + 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs index daa3161fa..b069bed10 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs @@ -21,6 +21,16 @@ namespace SqlSugar _Includes(this.Context, include1, include2, include3); return this; } + public ISugarQueryable IncludesByExpression4(Expression include1, Expression include2, Expression include3, Expression include4) + { + _Includes(this.Context, include1, include2, include3, include4); + return this; + } + public ISugarQueryable IncludesByExpression5(Expression include1, Expression include2, Expression include3, Expression include4, Expression include5) + { + _Includes(this.Context, include1, include2, include3, include4, include5); + return this; + } public ISugarQueryable IncludesByExpression(Expression include1) { _Includes(this.Context, include1); @@ -56,7 +66,44 @@ namespace SqlSugar method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast().ToArray()); return this; } - + public ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4) + { + var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression4") + .First(); + List parametres = new List(); + List types = new List(); + var entityInfo = this.EntityInfo; + method = GetIncludesByNameStringMethod(types, navMemberName, method, parametres, entityInfo); + //var navFirst = GetNavColumnInfo(navMemberName, entityInfo); + var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName2, method, parametres, entityInfo2); + var entityInfo3 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName3, method, parametres, entityInfo3); + var entityInfo4 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName4, method, parametres, entityInfo4); + method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast().ToArray()); + return this; + } + public ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4, string thenNavMemberName5) + { + var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression5") + .First(); + List parametres = new List(); + List types = new List(); + var entityInfo = this.EntityInfo; + method = GetIncludesByNameStringMethod(types, navMemberName, method, parametres, entityInfo); + //var navFirst = GetNavColumnInfo(navMemberName, entityInfo); + var entityInfo2 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName2, method, parametres, entityInfo2); + var entityInfo3 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName3, method, parametres, entityInfo3); + var entityInfo4 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName4, method, parametres, entityInfo4); + var entityInfo5 = this.Context.EntityMaintenance.GetEntityInfo(types.Last()); + method = GetIncludesByNameStringMethod(types, thenNavMemberName5, method, parametres, entityInfo5); + method.MakeGenericMethod(types.ToArray()).Invoke(this, parametres.Cast().ToArray()); + return this; + } private static MethodInfo GetIncludesByNameStringMethod(List types,string navMemberName, MethodInfo method, List parametres, EntityInfo entityInfo) { var navFirst = GetNavColumnInfo(navMemberName, entityInfo); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs index 853dfbb94..e3318c9e7 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/IncludesHelper.cs @@ -51,6 +51,44 @@ namespace SqlSugar if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List(); this.QueryBuilder.Includes.Add(navigat); } + private void _Includes(SqlSugarProvider context, params Expression[] expressions) + { + Func, List> SelectR1 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR2 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR3 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR4 = it => it.Select().ToList().Select(x => x as object).ToList(); + var navigat = new NavigatManager(); + navigat.SelectR1 = SelectR1; + navigat.SelectR2 = SelectR2; + navigat.SelectR3 = SelectR3; + navigat.SelectR4 = SelectR4; + navigat.Expressions = expressions; + navigat.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr; + navigat.CrossQueryItems = this.QueryBuilder.CrossQueryItems; + navigat.Context = this.Context; + if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List(); + this.QueryBuilder.Includes.Add(navigat); + } + private void _Includes(SqlSugarProvider context, params Expression[] expressions) + { + Func, List> SelectR1 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR2 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR3 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR4 = it => it.Select().ToList().Select(x => x as object).ToList(); + Func, List> SelectR5 = it => it.Select().ToList().Select(x => x as object).ToList(); + var navigat = new NavigatManager(); + navigat.SelectR1 = SelectR1; + navigat.SelectR2 = SelectR2; + navigat.SelectR3 = SelectR3; + navigat.SelectR4 = SelectR4; + navigat.SelectR5 = SelectR5; + navigat.Expressions = expressions; + navigat.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr; + navigat.CrossQueryItems = this.QueryBuilder.CrossQueryItems; + navigat.Context = this.Context; + if (this.QueryBuilder.Includes == null) this.QueryBuilder.Includes = new List(); + this.QueryBuilder.Includes.Add(navigat); + } public NavISugarQueryable AsNavQueryable() { return GetNavSugarQueryable(); diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs index 1060d47a5..3d3eb7c72 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs @@ -19,6 +19,8 @@ namespace SqlSugar ISugarQueryable IncludesByNameString(string navMemberName); ISugarQueryable IncludesByNameString(string navMemberName,string thenNavMemberName2); ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3); + ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4); + ISugarQueryable IncludesByNameString(string navMemberName, string thenNavMemberName2, string thenNavMemberName3, string thenNavMemberName4,string thenNavMemberName5); ISugarQueryable IncludesAllFirstLayer(params string[] ignoreProperyNameList); ISugarQueryable IncludesAllSecondLayer(Expression> expression,params string[] ignoreProperyNameList); ISugarQueryable Includes(Expression>> include1);