From 40e7b07537662e7ec8f4474e5f820aba3518cd7c Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 12 Apr 2022 12:59:43 +0800 Subject: [PATCH] Update SetContext --- .../QueryableProvider/QueryableProvider.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 1f78fadf7..0c1c3c462 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -1313,7 +1313,15 @@ namespace SqlSugar var entity = this.Context.EntityMaintenance.GetEntityInfo(); var queryableContext = this.Context.TempItems["Queryable_To_Context"] as MapperContext; var list = queryableContext.list; - var pkName = (((mappingFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name; + var pkName = ""; + if ((mappingFiled as LambdaExpression).Body is UnaryExpression) + { + pkName = (((mappingFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name; + } + else + { + pkName = ((mappingFiled as LambdaExpression).Body as MemberExpression).Member.Name; + } var key = thisFiled.ToString() +typeof(ParameterT).FullName + typeof(T).FullName; var ids = list.Select(it => it.GetType().GetProperty(pkName).GetValue(it)).ToArray(); if (queryableContext.TempChildLists == null) @@ -1332,7 +1340,15 @@ namespace SqlSugar }); queryableContext.TempChildLists[key]= result; } - var name = (((thisFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name; + var name = ""; + if((thisFiled as LambdaExpression).Body is UnaryExpression) + { + name = (((thisFiled as LambdaExpression).Body as UnaryExpression).Operand as MemberExpression).Member.Name; + } + else + { + name = ((thisFiled as LambdaExpression).Body as MemberExpression).Member.Name; + } var pkValue = parameter.GetType().GetProperty(pkName).GetValue(parameter); result = result.Where(it => it.GetType().GetProperty(name).GetValue(it).ObjToString() == pkValue.ObjToString()).ToList(); return result;