Aggregate function BUG

This commit is contained in:
sunkaixuan 2017-07-25 13:21:53 +08:00
parent e80a46b5f5
commit 89c3d0f174
4 changed files with 42 additions and 11 deletions

View File

@ -25,10 +25,40 @@ namespace OrmTest.UnitTest
Q3(); Q3();
Q4(); Q4();
q5(); q5();
q6();
q7();
} }
base.End("Method Test"); base.End("Method Test");
} }
private void q6()
{
using (var db = GetInstance())
{
var join6 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
}).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = SqlFunc.AggregateMin(sc.Id) }).ToSql();
string sql = @"SELECT [st].[Name] AS [Name] , MIN([sc].[Id]) AS [SchoolId] FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) ";
base.Check(sql, null, join6.Key, null, "join 6 Error");
}
}
private void q7()
{
using (var db = GetInstance())
{
var join7 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
}).Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = SqlFunc.AggregateMin(sc.Id*1) }).ToSql();
string sql = @"SELECT [st].[Name] AS [Name] , MIN(( [sc].[Id] * @Id0 )) AS [SchoolId] FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[Id] ) ";
base.Check(sql, new List<SugarParameter>() {
new SugarParameter("@Id0",1)
}, join7.Key, join7.Value, "join 7 Error");
}
}
private void q5() private void q5()
{ {
using (var db = GetInstance()) using (var db = GetInstance())

View File

@ -174,7 +174,8 @@ namespace SqlSugar
{ {
var appendValue = this.Context.SqlParameterKeyWord + ExpressionConst.Const + Context.ParameterIndex; var appendValue = this.Context.SqlParameterKeyWord + ExpressionConst.Const + Context.ParameterIndex;
Context.ParameterIndex++; Context.ParameterIndex++;
if (value != null && value.GetType().IsEnum()) { if (value != null && value.GetType().IsEnum())
{
value = Convert.ToInt64(value); value = Convert.ToInt64(value);
} }
this.Context.Parameters.Add(new SugarParameter(appendValue, value)); this.Context.Parameters.Add(new SugarParameter(appendValue, value));
@ -254,7 +255,7 @@ namespace SqlSugar
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName) protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
{ {
if (item.NodeType == ExpressionType.Constant) if (item is ConstantExpression)
{ {
this.Expression = item; this.Expression = item;
this.Start(); this.Start();
@ -280,12 +281,6 @@ namespace SqlSugar
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName)); parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData)); this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
} }
else if (item is MethodCallExpression)
{
this.Expression = item;
this.Start();
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
}
else if (item is MemberExpression) else if (item is MemberExpression)
{ {
if (this.Context.Result.IsLockCurrentParameter == false) if (this.Context.Result.IsLockCurrentParameter == false)
@ -397,6 +392,12 @@ namespace SqlSugar
} }
} }
} }
else if (item is MethodCallExpression|| item is UnaryExpression)
{
this.Expression = item;
this.Start();
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
}
else else
{ {
Check.ThrowNotSupportedException(item.GetType().Name); Check.ThrowNotSupportedException(item.GetType().Name);

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.2.1.9")] [assembly: AssemblyVersion("4.2.2")]
[assembly: AssemblyFileVersion("4.2.1.9")] [assembly: AssemblyFileVersion("4.2.2")]