From 35e520128de6f00f666d72cfd4bfbcd4b6b23a76 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 10 Aug 2022 14:07:06 +0800 Subject: [PATCH] Update exp to sql --- .../Subquery/Items/SubInnerJoin.cs | 1 + .../Subquery/Items/SubLeftJoin.cs | 1 + .../Subquery/Items/SubSelect.cs | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs index afe847314..ae7675d7a 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs @@ -46,6 +46,7 @@ namespace SqlSugar var name =this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters[0].Name); var parameter = (argExp as LambdaExpression).Parameters.Last(); Context.InitMappingInfo(parameter.Type); + this.Context.RefreshMapping(); var tableName= Context.GetTranslationTableName(parameter.Type.Name, true); var joinString =string.Format(" {2} INNER JOIN {1} {0} ", this.Context.GetTranslationColumnName(parameter.Name), diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs index dcbe48638..79cb43780 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs @@ -46,6 +46,7 @@ namespace SqlSugar var name =this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters[0].Name); var parameter = (argExp as LambdaExpression).Parameters.Last(); Context.InitMappingInfo(parameter.Type); + this.Context.RefreshMapping(); var tableName= Context.GetTranslationTableName(parameter.Type.Name, true); var joinString =string.Format(" {2} LEFT JOIN {1} {0} ", this.Context.GetTranslationColumnName(parameter.Name), diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs index 561cd79dc..37dcb8b47 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs @@ -43,12 +43,7 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - var entityType = (exp.Arguments[0] as LambdaExpression).Parameters[0].Type; - if (this.Context.InitMappingInfo != null) - { - this.Context.InitMappingInfo(entityType); - this.Context.RefreshMapping(); - } + InitType(exp); var result = ""; if (this.Context.JoinIndex == 0) result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle); @@ -60,6 +55,18 @@ namespace SqlSugar return result; } + private void InitType(MethodCallExpression exp) + { + foreach (var arg in (exp.Arguments[0] as LambdaExpression).Parameters) + { + if (this.Context.InitMappingInfo != null) + { + this.Context.InitMappingInfo(arg.Type); + this.Context.RefreshMapping(); + } + } + } + public void SetShortName(MethodCallExpression exp, string result) { if (exp.Arguments[0] is LambdaExpression && result.IsContainsIn("+", "-","*","/"))