Azure Cosmos DB .NET v3 SDK (Microsoft.Azure.Cosmos) examples for the SQL API
APPLIES TO:
SQL API
The azure-cosmos-dotnet-v3 GitHub repository includes the latest .NET sample solutions. You use these solutions to perform CRUD (create, read, update, and delete) and other common operations on Azure Cosmos DB resources.
If you're familiar with the previous version of the .NET SDK, you might be used to the terms collection and document. Because Azure Cosmos DB supports multiple API models, version 3.0 of the .NET SDK uses the generic terms container and item. A container can be a collection, graph, or table. An item can be a document, edge/vertex, or row, and is the content inside a container. This article provides:
- Links to the tasks in each of the example C# project files.
- Links to the related API reference content.
Prerequisites
Latest Visual Studio with the Azure development workload. You can get started with the free Visual Studio Community IDE. Enable the Azure development workload during Visual Studio setup.
An Azure subscription or free Azure Cosmos DB trial account.
- If you don't have an Azure subscription, create an Azure free account before you begin.
You can activate Visual Studio subscriber benefits. Your Visual Studio subscription gives you credits every month, which you can use for paid Azure services.
-
You can try Azure Cosmos DB for free, without an Azure subscription, and with no commitment required. Alternatively, you can create an Azure Cosmos DB free tier account, with the first 400 RU/s and 5 GB of storage for free. You can also use the Azure Cosmos DB emulator with a URI of
https://localhost:8081. For the key to use with the emulator, see Authenticating requests.
Note
The samples are self-contained, and set up and clean up after themselves. Each occurrence bills your subscription for one hour of usage in your container's performance tier.
Database examples
The RunDatabaseDemo method of the sample DatabaseManagement project shows how to do the following tasks. To learn about Azure Cosmos DB databases before you run the following samples, see Work with databases, containers, and items.
Container examples
The RunContainerDemo method of the sample ContainerManagement project shows how to do the following tasks. To learn about Azure Cosmos DB containers before you run the following samples, see Work with databases, containers, and items.
Item examples
The RunItemsDemo method of the sample ItemManagement project shows how to do the following tasks. To learn about Azure Cosmos DB items before you run the following samples, see Work with databases, containers, and items.
Indexing examples
The RunIndexDemo method of the sample IndexManagement project shows how to do the following tasks. To learn about indexing in Azure Cosmos DB before you run the following samples, see index policies, index types, and index paths.
| Task | API reference |
|---|---|
| Exclude an item from the index | IndexingDirective.Exclude |
| Use Lazy indexing | IndexingPolicy.IndexingMode |
| Exclude specified item paths from the index | IndexingPolicy.ExcludedPaths |
Query examples
The RunDemoAsync method of the sample Queries project shows how to do the following tasks, by using the SQL query grammar, the LINQ provider with query, and Lambda. To learn about the SQL query reference in Azure Cosmos DB before you run the following samples, see SQL query examples for Azure Cosmos DB.
Change feed examples
The RunBasicChangeFeed method of the sample ChangeFeed project shows how to do the following tasks. To learn about change feed in Azure Cosmos DB before you run the following samples, see Read Azure Cosmos DB change feed and Change feed processor.
Server-side programming examples
The RunDemoAsync method of the sample ServerSideScripts project shows how to do the following tasks. To learn about server-side programming in Azure Cosmos DB before you run the following samples, see Stored procedures, triggers, and user-defined functions.
Custom serialization
The SystemTextJson sample project shows how to use a custom serializer when you're initializing a new CosmosClient object. The sample also includes a custom CosmosSerializer class, which uses System.Text.Json for serialization and deserialization.
Next steps
Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.
If all you know is the number of vCores and servers in your existing database cluster, read about estimating request units by using vCores or vCPUs.
If you know typical request rates for your current database workload, read about estimating request units by using Azure Cosmos DB capacity planner.
Povratne informacije
Pošalјite i prikažite povratne informacije za