mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 04:53:45 +08:00
Support Subquery.Having
This commit is contained in:
@@ -153,6 +153,7 @@ namespace OrmTest
|
||||
JoinType.Left, o.Name == SqlFunc.ToString(SqlFunc.MergeString(",", i.Name, ","))
|
||||
))
|
||||
.Select<ViewOrder>().ToList();
|
||||
var test16 = db.Queryable<Order>().Select(it => SqlFunc.SqlServer_DateDiff("day", DateTime.Now.AddDays(-1), DateTime.Now)).ToList();
|
||||
Console.WriteLine("#### Examples End ####");
|
||||
}
|
||||
|
||||
@@ -242,8 +243,11 @@ namespace OrmTest
|
||||
.Where(i=>i.ItemId==1)
|
||||
.Any()
|
||||
).ToList();
|
||||
|
||||
var list3=db.Queryable<Order>().Select(it => SqlFunc.SqlServer_DateDiff("day", DateTime.Now.AddDays(-1), DateTime.Now)).ToList();
|
||||
;
|
||||
var list3 = db.Queryable<Order>().Select(it => new
|
||||
{
|
||||
customName = SqlFunc.Subqueryable<Custom>().Where(s=>s.Id==it.CustomId).GroupBy(s=>s.Name).Having(s=>SqlFunc.AggregateCount(s.Id)>0).Select(s => s.Name)
|
||||
}).ToList();
|
||||
|
||||
Console.WriteLine("#### Subquery End ####");
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SubHaving : ISubOperation
|
||||
{
|
||||
public bool HasWhere
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Having"; }
|
||||
}
|
||||
|
||||
public Expression Expression
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public int Sort
|
||||
{
|
||||
get
|
||||
{
|
||||
return 480;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpressionContext Context
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string GetValue(Expression expression)
|
||||
{
|
||||
var exp = expression as MethodCallExpression;
|
||||
var argExp = exp.Arguments[0];
|
||||
var result = "Having " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
|
||||
var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||
if (this.Context.JoinIndex == 0)
|
||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,8 @@ namespace SqlSugar
|
||||
new SubOrderBy(){ Context=Context },
|
||||
new SubOrderByDesc(){ Context=Context },
|
||||
new SubGroupBy(){ Context=Context},
|
||||
new SubAs(){Context=Context}
|
||||
new SubAs(){Context=Context},
|
||||
new SubHaving(){ Context=Context}
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -31,6 +31,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public Subqueryable<T> Having(Func<T, bool> expression)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public Subqueryable<T> Where<Main, Join1>(Func<Main, Join1, bool> expression)
|
||||
{
|
||||
return this;
|
||||
|
@@ -90,6 +90,7 @@
|
||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||
<Compile Include="Entities\SqlSguarTransaction.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAs.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubHaving.cs" />
|
||||
<Compile Include="Interface\ISugarRepository.cs" />
|
||||
<Compile Include="Interface\IParameterInsertable.cs" />
|
||||
<Compile Include="Abstract\InsertableProvider\ParameterInsertable.cs" />
|
||||
|
Reference in New Issue
Block a user