Azure页面分页的总记录数

huangapple go评论72阅读模式
英文:

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.");

"Azure页面分页的总记录数"

英文:

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(&quot;https://&lt;StorageName&gt;.table.core.windows.net/&quot;),&quot;&lt;TableName&gt;&quot;,new TableSharedKeyCredential(&quot;&lt;StorageName&gt;&quot;, &quot;&lt;AccessKey&gt;&quot;));

Pageable&lt;TableEntity&gt; totalRecords = tableClient.Query&lt;TableEntity&gt;();

Console.WriteLine($&quot;There are {totalRecords.Count()} records.&quot;);

Azure页面分页的总记录数

huangapple
  • 本文由 发表于 2023年5月25日 20:57:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332525.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定