Share via


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Database.CreateContainerAsync 方法

定义

重载

CreateContainerAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

CreateContainerAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

CreateContainerAsync(String, String, Nullable<Int32>, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

CreateContainerAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, Microsoft.Azure.Cosmos.ThroughputProperties throughputProperties, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : Microsoft.Azure.Cosmos.ContainerProperties * Microsoft.Azure.Cosmos.ThroughputProperties * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerAsync (containerProperties As ContainerProperties, throughputProperties As ThroughputProperties, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)

参数

containerProperties
ContainerProperties

ContainerProperties 对象。

throughputProperties
ThroughputProperties

(可选) 为容器预配的吞吐量,以测量 Azure Cosmos DB 服务中的每秒请求单位数。

requestOptions
RequestOptions

(可选) 请求的选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

包含 Task 的 , ContainerResponse 它包装 ContainerProperties 包含读取资源记录的 。

例外

如果未 containerProperties 设置 。

表示异步处理期间发生的故障的合并。 在 InnerExceptions 中查找实际异常 () 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建容器时可能会获取的一些常见代码包括:

StatusCode异常原因
400BadRequest - 这意味着所提供的请求出现问题。 很可能没有为新容器提供 ID。
403禁止 - 这意味着你尝试超过容器配额。 请联系支持人员以增加此配额。
409冲突 - 这表示 ContainerProperties ID 与所提供的 ID 匹配的 已存在。

示例

ContainerProperties containerProperties = new ContainerProperties()
{
    Id = Guid.NewGuid().ToString(),
    PartitionKeyPath = "/pk",
    IndexingPolicy = new IndexingPolicy()
   {
        Automatic = false,
        IndexingMode = IndexingMode.Lazy,
   }
};

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(
    containerProperties,
    ThroughputProperties.CreateAutoscaleThroughput(10000));

适用于

CreateContainerAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : Microsoft.Azure.Cosmos.ContainerProperties * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerAsync (containerProperties As ContainerProperties, Optional throughput As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)

参数

containerProperties
ContainerProperties

ContainerProperties 对象。

throughput
Nullable<Int32>

(可选) 为容器预配的吞吐量,以测量 Azure Cosmos DB 服务中的每秒请求单位数。

requestOptions
RequestOptions

(可选) 请求的选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

包含 Task 的 , ContainerResponse 它包装 ContainerProperties 包含读取资源记录的 。

例外

如果未 containerProperties 设置 。

表示异步处理期间发生的故障的合并。 在 InnerExceptions 中查找实际异常 () 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建容器时可能会获取的一些常见代码包括:

StatusCode异常原因
400BadRequest - 这意味着所提供的请求出现问题。 很可能没有为新容器提供 ID。
403禁止 - 这意味着你尝试超过容器配额。 请联系支持人员以增加此配额。
409冲突 - 这表示 ContainerProperties ID 与所提供的 ID 匹配的 已存在。

示例

ContainerProperties containerProperties = new ContainerProperties()
{
    Id = Guid.NewGuid().ToString(),
    PartitionKeyPath = "/pk",
    IndexingPolicy = new IndexingPolicy()
   {
        Automatic = false,
        IndexingMode = IndexingMode.Lazy,
   }
};

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(containerProperties);

注解

https://docs.microsoft.com/azure/cosmos-db/request-units 有关预配吞吐量的详细信息。

另请参阅

适用于

CreateContainerAsync(String, String, Nullable<Int32>, RequestOptions, CancellationToken)

在 Azure Cosmos 服务中将容器创建为异步操作。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (string id, string partitionKeyPath, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : string * string * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerAsync (id As String, partitionKeyPath As String, Optional throughput As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)

参数

id
String

Cosmos 容器 ID

partitionKeyPath
String

分区键的路径。 示例:/location

throughput
Nullable<Int32>

(可选) 为容器预配的吞吐量,以测量 Azure Cosmos DB 服务中的每秒请求单位数。

requestOptions
RequestOptions

(可选) 请求的选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

包含 Task 的 , ContainerResponse 它包装 ContainerProperties 包含读取资源记录的 。

例外

如果未 id 设置 。

表示异步处理期间发生的故障的合并。 在 InnerExceptions 中查找实际异常 () 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建容器时可能会获取的一些常见代码包括:

StatusCode异常原因
400BadRequest - 这意味着所提供的请求出现问题。 很可能没有为新容器提供 ID。
403禁止 - 这意味着你尝试超过容器配额。 请联系支持人员以增加此配额。
409冲突 - 这表示 ContainerProperties ID 与所提供的 ID 匹配的 已存在。

示例

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(Guid.NewGuid().ToString(), "/pk");

注解

https://docs.microsoft.com/azure/cosmos-db/request-units 有关预配吞吐量的详细信息。

另请参阅

适用于