Azure CosmosDB libraries for .NET

Overview

Azure CosmosDB is a distributed and scalable data store, supporting multiple different types of databases.

Get started with CosmosDB.

Client library

Use the CosmosDB .NET client library to access and store data in an existing CosmosDB data store. To automate creation of a new CosmosDB account, use the Azure portal, CLI, or PowerShell.

Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio Package Manager

Install-Package Microsoft.Azure.DocumentDB.Core

.NET Core CLI

dotnet add package Microsoft.Azure.DocumentDB.Core

Code Example

This example connects to an existing CosmosDB DocumentDB API database, reads a document from a collection, and deserializes it as an Item object.

/* Include this "using" directive...
using Microsoft.Azure.Documents.Client;
*/

DocumentClient client = new DocumentClient(endpointUri, authKeyString);
Uri documentUri = UriFactory.CreateDocumentUri("MyDatabaseName", "MyCollectionName", "DocumentId");
SomeClass myObject = client.ReadDocumentAsync<SomeClass>(documentUri).ToString()).Result;

Samples

View the complete list of Azure Cosmos DB samples.