mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 16:18:47 +08:00
Aggregate function BUG
This commit is contained in:
parent
e80a46b5f5
commit
89c3d0f174
@ -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())
|
||||||
|
@ -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));
|
||||||
@ -204,7 +205,7 @@ namespace SqlSugar
|
|||||||
protected string AppendParameter(object paramterValue)
|
protected string AppendParameter(object paramterValue)
|
||||||
{
|
{
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
this.Context.ParameterIndex++;;
|
this.Context.ParameterIndex++; ;
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
||||||
return parameterName;
|
return parameterName;
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
@ -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")]
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user