diff --git a/Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs b/Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs index 7507ad582..15242c4d2 100644 --- a/Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs +++ b/Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs @@ -147,6 +147,34 @@ namespace OrmTest.BugTest AbleQty = SqlFunc.ToInt32(ts.FQty - SqlFunc.Subqueryable().Where(s => s.FMICode == vmg.FMICode && s.FK_Store =="") .Select(s => SqlFunc.AggregateSum(s.FKCSL))) }).ToList(); + + var GoodsList2 = DB.Queryable((vmg, ts) => new object[] { + JoinType.Left,vmg.FMICode==ts.FMICode + }) + .Where((vmg, ts) => ts.FK_Store == "" && vmg.FMICode == vmg.FMICode) + .Select((vmg, ts) => new + { + PKID = vmg.PKID, + FMICode = vmg.FMICode, + FMIName = vmg.FMIName, + FGauge = vmg.FGauge, + FBIName = vmg.FBIName, + FK_FOrigin = vmg.FK_FOrigin, + FOEM = vmg.FOEM, + FSIName = vmg.FSIName, + FUIName = vmg.FUIName, + OutFQty = SqlFunc.ToInt32(ts.FQty) + , + InFQty = SqlFunc.Subqueryable().Where(s => s.FMICode == ts.FMICode && s.FK_Store == "").Select(s => SqlFunc.ToInt32(SqlFunc.IsNull(s.FQty, 0))) + , + TempQty = SqlFunc.IsNull(SqlFunc.Subqueryable().Where(s => s.FMICode == vmg.FMICode && s.FK_Store == "") + .GroupBy(s => new { s.FMICode, s.FK_Store }) + .OrderBy(s=>s.PKID) + .Select(s => SqlFunc.AggregateSum(SqlFunc.ToInt32(s.FKCSL))), 0) + , + AbleQty = ts.FQty - SqlFunc.Subqueryable().Where(s => s.FMICode == vmg.FMICode && s.FK_Store == "") + .Select(s => SqlFunc.AggregateSum(s.FKCSL)) + }).ToList(); } } /// diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubGroupBy.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubGroupBy.cs index 3b16cd944..1d00254ed 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubGroupBy.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubGroupBy.cs @@ -40,7 +40,12 @@ namespace SqlSugar { var exp = expression as MethodCallExpression; var argExp = exp.Arguments[0]; - var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle); + var type = ResolveExpressType.FieldSingle; + if ((argExp as LambdaExpression).Body is NewExpression) { + type = ResolveExpressType.ArraySingle; + } + var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp,type); + result = result.TrimEnd(','); var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot; result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context)); return result;