Exercise 3 – connecting to the Azure Cosmos DB SQL API with the SDK
In this section, we will explore Microsoft .NET SDL v3 for Azure Cosmos DB and explore the different methods and classes used to create different resources.
It is really simple to add the .NET SDK to your solution. Once we add the SDK to the project using NuGet by adding the Microsoft.Azure.Cosmos package, we will create a CosmosClient
. We need an endpoint and a master key for a Cosmos DB account, which we will retrieve and add to the CosmosClient
constructor. Now that the CosmosClient
class has been configured, we simply call methods on it to do whatever we need. We can create databases and containers, query documents, and run stored procedures, which means that we can do all operations that we can do in Data Explorer.
But how does it work? The SDK figures out how to set up the HTTP headers, make the REST call, and parse the response back from Cosmos DB. There is great flexibility in the types of objects...