diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index 7d48c21b3..9a042ac67 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -486,6 +486,31 @@ namespace SqlSugar )); } } + else if (!this.Context.IsJoin && (item is MemberInitExpression || item is NewExpression)) + { + List newExpressionInfos = new List(); + if (item is MemberInitExpression) + { + newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context); + } + else + { + newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context); + } + mappingKeys = new Dictionary(); + foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos) + { + //var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First(); + //asName = GetAsName(item, newExpressionInfo.ShortName, property); + mappingKeys.Add("Single_"+newExpressionInfo.LeftNameName,asName + "." + newExpressionInfo.RightDbName ); + CallContextThread>.SetData("Exp_Select_Mapping_Key", mappingKeys); + CallContextAsync>.SetData("Exp_Select_Mapping_Key", mappingKeys); + parameter.Context.Result.Append(this.Context.GetAsString( + this.Context.SqlTranslationLeft + asName + "." + newExpressionInfo.RightDbName + this.Context.SqlTranslationRight, + newExpressionInfo.RightDbName + )); + } + } else { asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType); diff --git a/Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs index ebb6abf68..6497ee24a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs @@ -168,7 +168,10 @@ namespace SqlSugar } catch { - result.Add(name, null); + if (!result.ContainsKey(name)) + { + result.Add(name, null); + } } } return result; @@ -447,6 +450,11 @@ namespace SqlSugar key = mappingKeys[item.Name]+"."+typeName + "." + name; info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower()); } + else if (mappingKeys != null && mappingKeys.ContainsKey("Single_" + name)) + { + key =mappingKeys["Single_" + name]; + info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower()); + } if (info == null&&oldInfo!=null) { info = oldInfo;