Browse Source

Update exp to sql

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
0c0322d447
  1. 28
      Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs
  2. 7
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubGroupBy.cs

28
Src/Asp.Net/SqlServerTest/BugTest/Bug2.cs

@ -147,6 +147,34 @@ namespace OrmTest.BugTest
AbleQty = SqlFunc.ToInt32(ts.FQty - SqlFunc.Subqueryable<TTempStock>().Where(s => s.FMICode == vmg.FMICode && s.FK_Store =="")
.Select(s => SqlFunc.AggregateSum(s.FKCSL)))
}).ToList();
var GoodsList2 = DB.Queryable<VMaterialInfo, TStock>((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<TStock>().Where(s => s.FMICode == ts.FMICode && s.FK_Store == "").Select(s => SqlFunc.ToInt32(SqlFunc.IsNull(s.FQty, 0)))
,
TempQty = SqlFunc.IsNull(SqlFunc.Subqueryable<TTempStock>().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<TTempStock>().Where(s => s.FMICode == vmg.FMICode && s.FK_Store == "")
.Select(s => SqlFunc.AggregateSum(s.FKCSL))
}).ToList();
}
}
/// <summary>

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

Loading…
Cancel
Save