satish kumar V satish kumar V - 1 year ago 267
C# Question

Paging in DocumentDB with Web application

This is the code that I am trying to implement paging for DocumentDB to get all the students in 10th class A section.

It is working fine in console application.

But when I am trying to do in my web application, at async call (i.e; query.ExecuteNextAsync()) the process is terminating and It even doesn't give any exception.

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(""), "authenticationKey==");
IDocumentQuery<Student> query;
String continuation = "";
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)
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;

I am not getting why it is executing in console application, but not in web application.

Anything wrong with this?

Or any better way to get the result?

Any help would be greatly appreciated.

Thanks in advance.

Answer Source

try using

FeedResponse pagedResults = query.ExecuteNextAsync().Result;

check this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download