From 957861022346f01efcd81eeb39e228bb0f44dfce Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 18 Apr 2023 12:39:50 +0800 Subject: [PATCH] Synchronization code --- .../Abstract/QueryableProvider/Includes.cs | 19 +++++++++++++++++++ .../SqlSugar/Interface/IIncludes.cs | 1 + 2 files changed, 20 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs index ec55ef6fa..4cabc3899 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/Includes.cs @@ -20,6 +20,25 @@ namespace SqlSugar _Includes(this.Context, include1); return this; } + public ISugarQueryable IncludesByNameString(string navMemberName) + { + var navs = this.EntityInfo.Columns.Where(it => it.Navigat != null&&it.PropertyName.EqualCase(navMemberName)).ToList(); + foreach (var item in navs) + { + var properyType = item.PropertyInfo.PropertyType; + var properyItemType = properyType; + if (properyType.FullName.IsCollectionsList()) + { + properyItemType = properyType.GetGenericArguments()[0]; + } + var exp = ExpressionBuilderHelper.CreateExpressionSelectField(typeof(T), item.PropertyName, properyType); + var method = this.GetType().GetMethods().Where(it => it.Name == "IncludesByExpression") + .First() + .MakeGenericMethod(properyItemType); + method.Invoke(this, new object[] { exp }); + } + return this; + } public ISugarQueryable IncludesAllFirstLayer(params string[] ignoreProperyNameList) { var navs=this.EntityInfo.Columns.Where(it => it.Navigat != null).ToList(); diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs index 512646bb2..964089b2e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IIncludes.cs @@ -16,6 +16,7 @@ namespace SqlSugar NavISugarQueryable AsNavQueryable(); ISugarQueryable IncludesByExpression2(Expression include1, Expression include2); ISugarQueryable IncludesByExpression(Expression include1); + ISugarQueryable IncludesByNameString(string navMemberName); ISugarQueryable IncludesAllFirstLayer(params string[] ignoreProperyNameList); ISugarQueryable IncludesAllSecondLayer(Expression> expression,params string[] ignoreProperyNameList); ISugarQueryable Includes(Expression>> include1);