From 02e14e60da4d703c3f8e81de37493c08467be953 Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Thu, 12 Sep 2024 23:56:19 +0800 Subject: [PATCH] =?UTF-8?q?:rocket:=20feat(=E6=96=B0=E5=A2=9E):=20?= =?UTF-8?q?=E6=89=8B=E5=86=99SQL=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/GitCommitMessageStorage.xml | 14 +++++++++++++- .../Context/Database/GetPagedResultAsync.cs | 4 ++-- Bunny.Dao/Entity/BaseEntity.cs | 2 ++ Bunny.Service/IService/Service/UserService.cs | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml index e4fd56a..3b56900 100644 --- a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml +++ b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml @@ -2,7 +2,19 @@ \ No newline at end of file diff --git a/Bunny.Common/Context/Database/GetPagedResultAsync.cs b/Bunny.Common/Context/Database/GetPagedResultAsync.cs index 28471e2..51feaa0 100644 --- a/Bunny.Common/Context/Database/GetPagedResultAsync.cs +++ b/Bunny.Common/Context/Database/GetPagedResultAsync.cs @@ -12,11 +12,11 @@ public static class GetPagedResultAsync return new PageResult(page, limit, total, items); } - public static async Task> GetPagedListFromSqlAsync(DbContext dbContext, string sql, string table, int page, int limit) + public static async Task> GetPagedListFromSqlAsync(DbContext dbContext, string sql, int page, int limit) where T : class { // 计算SQL查询的总数 - var total = await dbContext.Set().CountAsync(); + var total = dbContext.Set().Count(); // 执行分页查询 var paginatedSql = diff --git a/Bunny.Dao/Entity/BaseEntity.cs b/Bunny.Dao/Entity/BaseEntity.cs index 2e8537c..69a36eb 100644 --- a/Bunny.Dao/Entity/BaseEntity.cs +++ b/Bunny.Dao/Entity/BaseEntity.cs @@ -24,4 +24,6 @@ public class BaseEntity [Comment("并发版本")] [Column(TypeName = "datetime")] public DateTime Version { get; set; } + + // [NotMapped] public int Total { get; set; } } \ No newline at end of file diff --git a/Bunny.Service/IService/Service/UserService.cs b/Bunny.Service/IService/Service/UserService.cs index cca3da9..31cbc15 100644 --- a/Bunny.Service/IService/Service/UserService.cs +++ b/Bunny.Service/IService/Service/UserService.cs @@ -119,7 +119,7 @@ public class UserService : IUserService /// public Task> QueryPage(int page, int limit) { - var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync(DbContext, "select * from System_Users ", "System_Users", page, limit); + var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync(DbContext, "select * from System_Users ", page, limit); return pagedListAsync; } } \ No newline at end of file