Improvements under the hood – Asynchronous API in (Multi)DocumentQuery and ObjectQuery
In today’s article, I would like to introduce a new addition to our querying API. The DocumentQuery and ObjectQuery methods are now accompanied by asynchronous counterparts for query execution.
How to use the async API
The new asynchronous methods honor the Async suffix convention, so it is easy to spot them in the IntelliSense. The
GetEnumerableTypedResultAsync method has been added to both the DocumentQuery and ObjectQuery classes.
Assuming you have read the previous episode of this short article series, the method naming comes as no surprise. Since we have introduced support for DB reader based querying, the asynchronous counterpart of the reader-based methods only seems natural.
To provide you with a usage example, see the following snippet
var query = DocumentHelper.GetDocuments()
var pages = await query.GetEnumerableTypedResultAsync();
For brevity, I omitted an ObjectQuery usage example. It would be almost identical.
Both the CMS.DataEngine.DocumentQuery and CMS.DataEngine.ObjectQuery classes support asynchronous database querying. The GetEnumerableTypedResultAsync method is the starting point for such queries.
In the next article, we will shed light on a cool new addition to the API, which we have built on top of the asynchronous querying.