Skip to content

Instantly share code, notes, and snippets.

@deborahc
Last active August 9, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deborahc/9d877d51328fa39f6bda45c992778126 to your computer and use it in GitHub Desktop.
Save deborahc/9d877d51328fa39f6bda45c992778126 to your computer and use it in GitHub Desktop.
Getting started with Azure Cosmos DB .NET V3 SDK (GA)
using Microsoft.Azure.Cosmos;
using System;
using System.Threading.Tasks;
//Getting started with .NET SDK V3
namespace CosmosDotnetSDKGetStarted
{
class Program
{
static async Task Main(string[] args)
{
// Create new CosmosClient to communiciate with Azure Cosmos DB
using (var cosmosClient = new CosmosClient("endpoint", "key"))
{
// Create new database
Database database = await cosmosClient.CreateDatabaseIfNotExistsAsync("databaseId");
// Create new container
Container container = await database.CreateContainerIfNotExistsAsync("containerId", "/PartitionKey");
// Add item to container
var todoItem = new TodoItem()
{
id = Guid.NewGuid().ToString(),
PartitionKey = Guid.NewGuid().ToString(),
Task = "Get started with Azure Cosmos DB!"
};
var todoItemResponse = await container.CreateItemAsync<TodoItem>(todoItem, new PartitionKey(todoItem.PartitionKey));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment