diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index eca69da28..f7349daea 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -753,18 +753,7 @@ namespace SqlSugar } public virtual List ToPageList(int pageIndex, int pageSize) { - if (pageIndex == 0) - pageIndex = 1; - if (QueryBuilder.PartitionByValue.HasValue()) - { - QueryBuilder.ExternalPageIndex = pageIndex; - QueryBuilder.ExternalPageSize = pageSize; - } - else - { - QueryBuilder.Skip = (pageIndex - 1) * pageSize; - QueryBuilder.Take = pageSize; - } + pageIndex = _PageList(pageIndex, pageSize); return ToList(); } public virtual List ToPageList(int pageIndex, int pageSize, ref int totalNumber) @@ -1003,14 +992,26 @@ namespace SqlSugar return _ToListAsync(); } - public Task ToJsonAsync() + public async Task ToJsonAsync() { - return Task.FromResult(ToJson()); + if (IsCache) + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + var result = CacheSchemeMain.GetOrCreate(cacheService, this.QueryBuilder, () => + { + return this.Context.Utilities.SerializeObject(this.ToList(), typeof(T)); + }, CacheTime, this.Context); + return result; + } + else + { + return this.Context.Utilities.SerializeObject(await this.ToListAsync(), typeof(T)); + } } - public Task ToJsonPageAsync(int pageIndex, int pageSize) + public async Task ToJsonPageAsync(int pageIndex, int pageSize) { - return Task.FromResult(ToJsonPage(pageIndex, pageSize)); + return this.Context.Utilities.SerializeObject(await this.ToPageListAsync(pageIndex, pageSize), typeof(T)); } public Task ToJsonPageAsync(int pageIndex, int pageSize, ref int totalNumber) @@ -1035,7 +1036,8 @@ namespace SqlSugar public Task> ToPageListAsync(int pageIndex, int pageSize) { - return Task.FromResult(ToPageList(pageIndex, pageSize)); + pageIndex = _PageList(pageIndex, pageSize); + return ToListAsync(); } public Task> ToPageListAsync(int pageIndex, int pageSize, ref int totalNumber) @@ -1089,6 +1091,23 @@ namespace SqlSugar return this; } } + private int _PageList(int pageIndex, int pageSize) + { + if (pageIndex == 0) + pageIndex = 1; + if (QueryBuilder.PartitionByValue.HasValue()) + { + QueryBuilder.ExternalPageIndex = pageIndex; + QueryBuilder.ExternalPageSize = pageSize; + } + else + { + QueryBuilder.Skip = (pageIndex - 1) * pageSize; + QueryBuilder.Take = pageSize; + } + + return pageIndex; + } protected ISugarQueryable _GroupBy(Expression expression) { QueryBuilder.CheckExpression(expression, "GroupBy");