英文:
Total record count for Azure page pagination
问题
以下是翻译好的部分:
如果我们看一下以下的代码片段:
var pages = TableClient.QueryAsync<Entity>(maxPerPage: 10).AsPages(continuationToken);
await foreach (var page in pages)
{
return page;
}
这将返回所有记录作为分页,并返回一个单独的页面,允许我为表格分页带回用户请求的页面。
它不允许我在末尾添加计数,因为那不会返回总记录数。Azure 分页对象中也不提供总记录数。我在网上搜索的地方表明 Azure 存储不提供总记录数。
我不想逐个记录地遍历,也不想进行第二次调用以获取所有记录并计数它们。
我想知道是否有其他人遇到过这个问题,以及他们是如何解决的?
英文:
If we take the follow bit of code
var pages = TableClient.QueryAsync<Entity>(maxPerPage: 10).AsPages(continuationToken);
await foreach (var page in pages)
{
return page;
}
This brings back all the records as pages and returns a single page and allows me to bring back the page the user has request for table pagination.
It wont allow me to add a count on the end as that wont bring back the total record count. Nor does it offer it in the azure pages object. Where I have looked online states that azure storage doesn't offer a total record count.
I dont want to go through each record and I dont want a second call to get all and count them either.
I was wondering if someone else had come across this issue and what their work around was?
答案1
得分: 1
以下是您要翻译的部分:
"As you have mentioned there is no direct way that you can achieve count using the mentioned code. However, After reproducing from my end, I could able to retrieve the records count using the below piece of code."
"如您所提到,使用上述代码没有直接的方法可以实现计数。但是,在我的端上重现之后,我能够使用以下代码检索记录计数。"
var tableClient = new TableClient(new Uri("https://<StorageName>.table.core.windows.net/"),"<TableName>",new TableSharedKeyCredential("<StorageName>", "<AccessKey>"));
Pageable<TableEntity> totalRecords = tableClient.Query<TableEntity>();
Console.WriteLine($"There are {totalRecords.Count()} records.");
""
英文:
As you have mentioned there is no direct way that you can achieve count using the mentioned code. However, After reproducing from my end, I could able to retrieve the records count using the below piece of code.
var tableClient = new TableClient(new Uri("https://<StorageName>.table.core.windows.net/"),"<TableName>",new TableSharedKeyCredential("<StorageName>", "<AccessKey>"));
Pageable<TableEntity> totalRecords = tableClient.Query<TableEntity>();
Console.WriteLine($"There are {totalRecords.Count()} records.");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论