Optimized code (Select DTO)

This commit is contained in:
sunkaixuan
2023-04-16 15:47:53 +08:00
parent 6b4923adeb
commit 23e9e6432c
4 changed files with 5 additions and 10 deletions

View File

@@ -973,6 +973,7 @@ namespace SqlSugar
public bool NoCheckInclude { get; set; } public bool NoCheckInclude { get; set; }
public virtual bool IsSelectNoAll { get; set; } = false; public virtual bool IsSelectNoAll { get; set; } = false;
public List<string> AutoAppendedColumns { get; set; } public List<string> AutoAppendedColumns { get; set; }
public Dictionary<string, string> MappingKeys { get; set; }
#endregion #endregion
private string GetTableName(string entityName) private string GetTableName(string entityName)

View File

@@ -9,6 +9,6 @@ namespace SqlSugar
public class ExpressionOutParameter public class ExpressionOutParameter
{ {
public SqlSugarProvider Context { get; set; } public SqlSugarProvider Context { get; set; }
public QueryBuilder QueryBuilder { get; set; } public QueryBuilder QueryBuilder { get; set; }
} }
} }

View File

@@ -122,14 +122,12 @@ namespace SqlSugar
mappingKeys.Add("Single_" + newExpressionInfo.LeftNameName, asName + "." + newExpressionInfo.LeftNameName); mappingKeys.Add("Single_" + newExpressionInfo.LeftNameName, asName + "." + newExpressionInfo.LeftNameName);
if (newExpressionInfo.Type == nameof(ConstantExpression)) if (newExpressionInfo.Type == nameof(ConstantExpression))
{ {
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys); this.Context.SugarContext.QueryBuilder.MappingKeys = mappingKeys;
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
parameter.Context.Result.Append($" {newExpressionInfo.RightDbName} AS {this.Context.SqlTranslationLeft}{asName}.{newExpressionInfo.LeftNameName}{this.Context.SqlTranslationRight} "); parameter.Context.Result.Append($" {newExpressionInfo.RightDbName} AS {this.Context.SqlTranslationLeft}{asName}.{newExpressionInfo.LeftNameName}{this.Context.SqlTranslationRight} ");
} }
else else
{ {
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys); this.Context.SugarContext.QueryBuilder.MappingKeys = mappingKeys;
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
parameter.Context.Result.Append(this.Context.GetAsString( parameter.Context.Result.Append(this.Context.GetAsString(
this.Context.SqlTranslationLeft + asName + "." + newExpressionInfo.LeftNameName + this.Context.SqlTranslationRight, this.Context.SqlTranslationLeft + asName + "." + newExpressionInfo.LeftNameName + this.Context.SqlTranslationRight,
newExpressionInfo.RightDbName newExpressionInfo.RightDbName

View File

@@ -368,11 +368,7 @@ namespace SqlSugar
private Dictionary<string, object> DataReaderToList<T>(IDataReader reader, Type tType, List<PropertyInfo> classProperties, List<T> reval) private Dictionary<string, object> DataReaderToList<T>(IDataReader reader, Type tType, List<PropertyInfo> classProperties, List<T> reval)
{ {
var readerValues = DataReaderToDictionary(reader, tType); var readerValues = DataReaderToDictionary(reader, tType);
var mappingKeys = CallContextThread<Dictionary<string, string>>.GetData("Exp_Select_Mapping_Key"); var mappingKeys = this.QueryBuilder.MappingKeys;
if (mappingKeys == null)
{
mappingKeys = CallContextAsync<Dictionary<string, string>>.GetData("Exp_Select_Mapping_Key");
}
var result = new Dictionary<string, object>(); var result = new Dictionary<string, object>();
foreach (var item in classProperties) foreach (var item in classProperties)
{ {