diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs index 59fa5c51d..137647595 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "MAX("+SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle)+")"; + var argExp = exp.Arguments[0]; + var result = "MAX(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs index 5d51fbb3f..5636b6a20 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "MIN(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")"; + var argExp = exp.Arguments[0]; + var result = "MIN(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs index 00b212cad..cd757de22 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs @@ -6,7 +6,7 @@ using System.Text; namespace SqlSugar { - public class SubSum:ISubOperation + public class SubSum : ISubOperation { public bool HasWhere { @@ -43,7 +43,11 @@ namespace SqlSugar public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; - return "SUM("+SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle)+")"; + var argExp = exp.Arguments[0]; + var result = "SUM(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple)+")"; + var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; + result = result.Replace(selfParameterName, string.Empty); + return result; } } }