Browse Source

SubQuery .Sum(it=>(int)it.XX) BUG

pull/12/MERGE
610262374@qq.com 6 years ago
parent
commit
f6d3241d1d
  1. 21
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 7
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs
  3. 7
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs
  4. 7
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs

21
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -94,6 +94,27 @@ namespace OrmTest.Demo
Id = SqlFunc.Subqueryable<School>().Where(s => s.Id == it.Id).Select(s => s.Id)
}).ToList();
var getAll6 = db.Queryable<Student>().Select(it =>
new
{
name = it.Name,
id = SqlFunc.Subqueryable<Student>().Where(s => s.Id == it.Id).Sum(s => (int)s.SchoolId)
}).ToList();
var getAll66 = db.Queryable<Student>().Select(it =>
new
{
name = it.Name,
id = SqlFunc.Subqueryable<Student>().Where(s => s.Id == it.Id).Sum(s =>s.SchoolId.Value)
}).ToList();
var getAll666 = db.Queryable<Student>().Select(it =>
new
{
name = it.Name,
id = SqlFunc.Subqueryable<Student>().Where(s => s.Id == it.Id).Min(s => s.Id)
}).ToList();
}
private static void Async()

7
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMax.cs

@ -44,8 +44,13 @@ namespace SqlSugar
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var parametres = (argExp as LambdaExpression).Parameters;
if ((argExp as LambdaExpression).Body is UnaryExpression)
{
argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand;
}
var result = "MAX(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")";
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, string.Empty);
return result;
}

7
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubMin.cs

@ -44,8 +44,13 @@ namespace SqlSugar
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var parametres = (argExp as LambdaExpression).Parameters;
if ((argExp as LambdaExpression).Body is UnaryExpression)
{
argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand;
}
var result = "MIN(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")";
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, string.Empty);
return result;
}

7
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSum.cs

@ -44,8 +44,13 @@ namespace SqlSugar
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var parametres = (argExp as LambdaExpression).Parameters;
if ((argExp as LambdaExpression).Body is UnaryExpression)
{
argExp =((argExp as LambdaExpression).Body as UnaryExpression).Operand;
}
var result = "SUM(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple)+")";
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, string.Empty);
return result;
}

Loading…
Cancel
Save