Update ContextMethods

This commit is contained in:
sunkaixuan 2022-08-31 13:22:17 +08:00
parent 9a14754d85
commit ea65c545d5
2 changed files with 34 additions and 1 deletions

View File

@ -486,6 +486,31 @@ namespace SqlSugar
));
}
}
else if (!this.Context.IsJoin && (item is MemberInitExpression || item is NewExpression))
{
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
if (item is MemberInitExpression)
{
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context);
}
else
{
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context);
}
mappingKeys = new Dictionary<string, string>();
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<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
CallContextAsync<Dictionary<string, string>>.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);

View File

@ -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;