Browse Source

Query PartitionBy

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
f38654dd34
  1. 5
      SqlServerTest/Demos/Query.cs
  2. 2
      SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 11
      SqlSugar/Abstract/SqlBuilderProvider/Detail/QueryBuilder.cs

5
SqlServerTest/Demos/Query.cs

@ -102,6 +102,11 @@ namespace OrmTest.Demo
.GroupBy(it => new { it.Id, it.Name }).Having(it => SqlFunc.AggregateAvg(it.Id) > 0)
.Select(it => new { idAvg = SqlFunc.AggregateAvg(it.Id), name = it.Name }).ToList();
// group id,name take first
var list3 = db.Queryable<Student>()
.PartitionBy(it => new { it.Id, it.Name }).Take(1).ToList();
//SQL:
//SELECT AVG([Id]) AS[idAvg], [Name] AS[name] FROM[Student] GROUP BY[Name],[Id] HAVING(AVG([Id]) > 0 )

2
SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -258,6 +258,8 @@ namespace SqlSugar
public ISugarQueryable<T> PartitionBy(Expression<Func<T, object>> expression)
{
if (QueryBuilder.Take == null)
QueryBuilder.Take = 0;
_PartitionBy(expression);
return this;
}

11
SqlSugar/Abstract/SqlBuilderProvider/Detail/QueryBuilder.cs

@ -226,16 +226,27 @@ namespace SqlSugar
if (Skip != null && Take == null)
{
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
if (this.PartitionByValue.IsValuable()) {
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, long.MaxValue);
}
else if (Skip == null && Take != null)
{
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, 1, Take.ObjToInt());
}
else if (Skip != null && Take != null)
{
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() ";
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt());
}
else

Loading…
Cancel
Save