gpt4 book ai didi

c# - 使用 Web 应用程序在 DocumentDB 中进行分页

转载 作者:行者123 更新时间:2023-11-30 19:57:43 25 4
gpt4 key购买 nike

这是我尝试为 DocumentDB 实现分页的代码,以获取 10 年级 A 部分的所有学生。

它在控制台应用程序中运行良好。

但是当我尝试在我的网络应用程序中执行异步调用(即 query.ExecuteNextAsync())时,该进程正在终止,甚至没有给出任何异常。

public List<Student> allStudents()
{
int class = 10;
string section = "A";
string documentType = "Student";
List<Student> students = new List<Student>();
string DocumentDBCollectionLink = "CollectionLink";
DocumentClient dc = new DocumentClient(new Uri("https://xyz.documents.azure.com:443/"), "authenticationKey==");
IDocumentQuery<Student> query;
String continuation = "";
do
{
FeedOptions feedOptions = new FeedOptions { MaxItemCount = 10, RequestContinuation = continuation };
query = dc.CreateDocumentQuery<Student>(DocumentDBCollectionLink, feedOptions).Where(d => d.Type.Equals(documentType) && d.Class.Equals(class) && d.Section.Equals(section)).AsDocumentQuery();

FeedResponse<Student> pagedResults = this.getRecords(query).Result;
foreach (Student system in pagedResults)
{
students.Add(system);
}
continuation = pagedResults.ResponseContinuation;
} while (!String.IsNullOrEmpty(continuation));
return students;
}
private async Task<FeedResponse<Student>> getRecords(IDocumentQuery<Student> query)
{
FeedResponse<Student> pagedResults = await query.ExecuteNextAsync<Student>();
return pagedResults;
}

我不明白为什么它在控制台应用程序中执行,但不在 Web 应用程序中执行。

这有什么问题吗?

或者有更好的方法来获得结果吗?

任何帮助将不胜感激。

提前致谢。

最佳答案

尝试使用

FeedResponse pagedResults = query.ExecuteNextAsync().Result;

检查一下

关于c# - 使用 Web 应用程序在 DocumentDB 中进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28983121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com