Creating a container

To create the container, add the following:

  1. Copy and paste the CreateContainerAsync method below your CreateDatabaseAsync method. CreateContainerAsync creates a new container with the FamilyContainer ID, if it doesn't already exist, by using the ID specified from the containerId field partitioned by the LastName property:
 private async Task CreateContainerAsync()
{
// Create a new container
this.container = await this.database.CreateContainerIfNotExistsAsync(containerId, "/LastName");
Console.WriteLine("Created Container: {0} ", this.container.Id);
}
  1. In the GetStartedDemoAsync method, you should now add the line of code to call the CreateContainerAsync method. The method will now look like the following:
 public async Task GetStartedDemoAsync()
{
// Create a new instance of the Cosmos Client
this.cosmosClient = new CosmosClient(EndpointUri, PrimaryKey);
await this.CreateDatabaseAsync();

//ADD THIS PART TO YOUR CODE
await this.CreateContainerAsync();
}
  1. You can now run the application again, and you will see that the container is created. 

In the next section, we are going to add items to the container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset