Last active
August 9, 2019 17:25
-
-
Save deborahc/9d877d51328fa39f6bda45c992778126 to your computer and use it in GitHub Desktop.
Getting started with Azure Cosmos DB .NET V3 SDK (GA)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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