🚀 feat(新增): 手写SQL分页查询完成
This commit is contained in:
parent
ce8c83b7a8
commit
02e14e60da
|
@ -2,7 +2,19 @@
|
|||
<project version="4">
|
||||
<component name="GitCommitMessageStorage">
|
||||
<option name="messageStorage">
|
||||
<MessageStorage />
|
||||
<MessageStorage>
|
||||
<option name="commitTemplate">
|
||||
<CommitTemplate>
|
||||
<option name="body" value="" />
|
||||
<option name="changes" value="" />
|
||||
<option name="closes" value="" />
|
||||
<option name="scope" value="" />
|
||||
<option name="skipCi" value="" />
|
||||
<option name="subject" value="" />
|
||||
<option name="type" value="feat" />
|
||||
</CommitTemplate>
|
||||
</option>
|
||||
</MessageStorage>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -12,11 +12,11 @@ public static class GetPagedResultAsync
|
|||
return new PageResult<T>(page, limit, total, items);
|
||||
}
|
||||
|
||||
public static async Task<PageResult<T>> GetPagedListFromSqlAsync<T>(DbContext dbContext, string sql, string table, int page, int limit)
|
||||
public static async Task<PageResult<T>> GetPagedListFromSqlAsync<T>(DbContext dbContext, string sql, int page, int limit)
|
||||
where T : class
|
||||
{
|
||||
// 计算SQL查询的总数
|
||||
var total = await dbContext.Set<T>().CountAsync();
|
||||
var total = dbContext.Set<T>().Count();
|
||||
|
||||
// 执行分页查询
|
||||
var paginatedSql =
|
||||
|
|
|
@ -24,4 +24,6 @@ public class BaseEntity
|
|||
[Comment("并发版本")]
|
||||
[Column(TypeName = "datetime")]
|
||||
public DateTime Version { get; set; }
|
||||
|
||||
// [NotMapped] public int Total { get; set; }
|
||||
}
|
|
@ -119,7 +119,7 @@ public class UserService : IUserService
|
|||
/// <param name="limit"></param>
|
||||
public Task<PageResult<Users>> QueryPage(int page, int limit)
|
||||
{
|
||||
var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync<Users>(DbContext, "select * from System_Users ", "System_Users", page, limit);
|
||||
var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync<Users>(DbContext, "select * from System_Users ", page, limit);
|
||||
return pagedListAsync;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue