Question:
You are a software developer tasked with creating a C# utility that interacts with Azure Cosmos DB. Your script should establish a connection, create a database and a container if they don't exist, and finally create an item in the container. Use placeholders like "<connection-string>", "<database>", "<container>".
Answer:
var cosmosClient = new CosmosClient("<connection-string>");
// Create a database
var database = await cosmosClient.CreateDatabaseIfNotExistsAsync("<database>");
// Create a container
var container = await database.CreateContainerIfNotExistsAsync("<container>", "/mypartitionkey");
// Create an item
dynamic testItem = new
{
id = "1",
mypartitionkey = "mypartitionvalue",
description = "mydescription"
};
await container.CreateItemAsync(testItem, new PartitionKey(testItem.mypartitionkey));