Browse Source

Update access

pull/14/head
sunkaixuan 3 years ago
parent
commit
b9da3f285d
  1. 6
      Src/Asp.Net/AccessTest/Demo/Demo1_Queryable.cs
  2. 35
      Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessQueryBuilder.cs

6
Src/Asp.Net/AccessTest/Demo/Demo1_Queryable.cs

@ -100,7 +100,9 @@ namespace OrmTest
Console.WriteLine("#### Examples Start ####");
var db = GetInstance();
var dbTime = db.GetDate();
var getAll = db.Queryable<Order>().Where(it=> SqlFunc.EqualsNull(it.Name,null)).ToList();
var getAll = db.Queryable<Order>().ToList();
var getTake = db.Queryable<Order>().Take(2).ToList();
var getSkip = db.Queryable<Order>().Skip(2).ToList();
var getOrderBy = db.Queryable<Order>().OrderBy(it => it.Name,OrderByType.Desc).ToList();
var getOrderBy2 = db.Queryable<Order>().OrderBy(it => it.Id).OrderBy(it => it.Name, OrderByType.Desc).ToList();
var getOrderBy3 = db.Queryable<Order>().OrderBy(it =>new { it.Name,it.Id}).ToList();
@ -135,7 +137,7 @@ namespace OrmTest
//test09.Wait();
int c = 0;
var test10 = db.Queryable<Order>().ToPageList(1, 2, ref c);
var test10 = db.Queryable<Order>().OrderBy(it=>it.Id).ToPageList(3,5, ref c);
var test11 = db.Queryable<Order>().GroupBy(it=>new { it.CreateTime.Year }).Select(it=>it.CreateTime.Year).ToList();
// var test12 = db.Queryable<Order>().GroupBy(it => it.CreateTime.Date ).Select(it => it.CreateTime.Date).ToList();
//var test13 = db.Queryable<Order>().GroupBy(it => new { it.CreateTime.Date ,it.CreateTime.Year,it.CreateTime.Minute })

35
Src/Asp.Net/SqlSugar.Access/Access/SqlBuilder/AccessQueryBuilder.cs

@ -26,12 +26,14 @@ namespace SqlSugar.Access
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY now() ";
if (this.PartitionByValue.HasValue())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
throw new Exception("sqlite no support partition by");
}
var isFirst = (Skip == 0 || Skip == null) && Take == 1 && DisableTop == false;
var isRowNumber = (Skip != null || Take != null) && !isFirst;
var isPage = isRowNumber;
isRowNumber = false;
var oldSkip = Skip;
var oldTake = Take;
Skip = null;
Take = null;
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
@ -44,12 +46,7 @@ namespace SqlSugar.Access
var result = isFirst ? sql.ToString() : ToPageSql(sql.ToString(), this.Take, this.Skip);
if (ExternalPageIndex > 0)
{
if (externalOrderBy.IsNullOrEmpty())
{
externalOrderBy = " ORDER BY now() ";
}
result = string.Format("SELECT *,ROW_NUMBER() OVER({0}) AS RowIndex2 FROM ({1}) ExternalTable ", GetExternalOrderBy(externalOrderBy), result);
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true);
throw new Exception("sqlite no support partition by");
}
this.OrderByValue = oldOrderBy;
if (!string.IsNullOrEmpty(this.Offset))
@ -57,10 +54,34 @@ namespace SqlSugar.Access
if (this.OrderByValue.IsNullOrEmpty())
{
result += " ORDER BY now() ";
this.OrderByValue = " ORDER BY now() ";
}
result += this.Offset;
}
result = GetSqlQuerySql(result);
if (isPage)
{
var colums=this.Context.EntityMaintenance.GetEntityInfo(this.EntityType).Columns;
if (!colums.Any(x => x.IsPrimarykey))
{
throw new Exception("sqlite page need primary key , entity name: "+ this.EntityName);
}
var pkName =this.Builder.GetTranslationColumnName(colums.Where(x => x.IsPrimarykey).First().DbColumnName);
var takeSql = $@" SELECT { (oldTake == null ? "" : ("Top " + oldTake)) }
*FROM({ result}) ACCTABLE1";
var skipSql = $@"
WHERE {pkName} NOT IN
(SELECT { (oldSkip == null ? "" : ("Top " + oldSkip))} {pkName} FROM ({result}) ACCTABLE2 { this.OrderByValue })";
if (oldSkip == 0)
{
result = takeSql;
}
else
{
result = takeSql+skipSql;
}
}
return result;
}
}

Loading…
Cancel
Save