To delete a Family item, take the following steps:
- Add the DeleteFamilyItemAsync method after your ReplaceFamilyItemAsync method:
private async Task DeleteFamilyItemAsync()
{
var partitionKeyValue = "Zaal";
var familyId = "Zaal.1";
// Delete an item. Note we must provide the partition key value and id of the item to delete
_ = await this.container.DeleteItemAsync<Family>(familyId, new PartitionKey(partitionKeyValue));
Console.WriteLine("Deleted Family [{0},{1}] ", partitionKeyValue, familyId);
}
- Then, add a call to DeleteFamilyItemAsync in the GetStartedDemoAsync method:
public async Task GetStartedDemoAsync()
{
// Create a new instance of the Cosmos Client
this.cosmosClient = new CosmosClient(EndpointUri, PrimaryKey);
await this.CreateDatabaseAsync();
await this.CreateContainerAsync();
await this.AddItemsToContainerAsync();
await this.QueryItemsAsync();
await this.ReplaceFamilyItemAsync();
//ADD THIS PART TO YOUR CODE
await this.DeleteFamilyItemAsync();
}
- Run the application, and you will see that the item is deleted.
In this demo, we created a Cosmos DB server, database, and container. We also added data to the container, ran a query on the data, updated the data, and lastly, we deleted the data.
In the next section, we are going to cover partitioning schemes.