Share via


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

Database.DefineContainer(String, String) 方法

定义

创建 containerBuilder。

public abstract Microsoft.Azure.Cosmos.Fluent.ContainerBuilder DefineContainer (string name, string partitionKeyPath);
abstract member DefineContainer : string * string -> Microsoft.Azure.Cosmos.Fluent.ContainerBuilder
Public MustOverride Function DefineContainer (name As String, partitionKeyPath As String) As ContainerBuilder

参数

name
String

要创建的 Azure Cosmos 容器名称。

partitionKeyPath
String

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

返回

Azure Cosmos 容器的 Fluent 定义。

示例

CosmosContainerResponse container = await this.cosmosDatabase.DefineContainer("TestContainer", "/partitionKey")
    .UniqueKey()
        .Path("/path1")
        .Path("/path2")
        .Attach()
    .IndexingPolicy()
        .IndexingMode(IndexingMode.Consistent)
        .AutomaticIndexing(false)
        .IncludedPaths()
            .Path("/includepath1")
            .Path("/includepath2")
            .Attach()
        .ExcludedPaths()
            .Path("/excludepath1")
            .Path("/excludepath2")
            .Attach()
        .CompositeIndex()
            .Path("/root/leaf1")
            .Path("/root/leaf2", CompositePathSortOrder.Descending)
            .Attach()
        .CompositeIndex()
            .Path("/root/leaf3")
            .Path("/root/leaf4")
            .Attach()
        .Attach()
    .CreateAsync(5000 /* throughput /*); 

适用于