New Data Provider for Azure Cosmos Database

Azure Cosmos DB is a fully managed Microsoft NoSQL database for modern app development, which is growing in popularity. Various APIs are available for connecting to Cosmos DB, as for example SQL API, Cassandra API or MongoDB API. Since we’re already able to connect to MongoDB or Cassandra through their own data providers, we’ll use the SQL API for the provider.

Azure Cosmos DB creates resources in a hierarchy consisting of accounts, databases, containers and items:

First Steps

First, you’ll add a reference to the combit.ListLabel28.CosmosDBDataProvider.dll within your project (or use the equivalent NuGet package). Additionally, you’ll need the Microsoft.Azure.Cosmos NuGet package.

To establish a connection, all you have to do is create an instance of the CosmosDbDataProvider and provide the connection information in the constructor:

CosmosDbDataProvider<Family> provider = new CosmosDbDataProvider<Family>(<YourEndpointUri>, <YourPrimaryKey>, <databaseId>, <containerId>);
ListLabel LL = new ListLabel();
LL.DataSource = provider;


Right here, a type for the generic provider class must be specified, which corresponds to the class or the record type of the element in the container. In the above example, this is the “Family” class. You’d also specify this type when you write elements into the container, or retrieve them from the container. For more information on the SQL API, please see Quickstart: Azure Cosmos DB for NoSQL Client Library for .NET.

Example: an element of the “Family” class in the Azure-Cosmos-DB container would look like this:

In the List & Label Designer, you’ll find this structure and can use it together with the relations in your report:

Optional Parameter

By using the instance we created above, you’ll receive all elements (items) that are included in the container. In order to only get certain elements (items), you’d pass an optional parameter to the constructor:

string sqlQuery = "SELECT * FROM c WHERE c.Name = 'Anderson'";
CosmosDbDataProvider<Family> provider = new CosmosDbDataProvider<Family>(<YourEndpointUri>, <YourPrimaryKey>, <databaseId>, <containerId>, sqlQuery);
ListLabel LL = new ListLabel();
LL.DataSource = provider;

The resulting report will only show the records where “Name” property matches “Anderson”. This gives you full flexibility to adjust the amount of data to your needs.

How to visualize your data from Azure Cosmos databases with List & Label Designer.

Related Posts

Leave a Comment