Share via


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

Container.ReadManyItemsStreamAsync 方法

定义

使用 Id 和 PartitionKey 值从容器中读取多个项。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage> ReadManyItemsStreamAsync (System.Collections.Generic.IReadOnlyList<(string id, Microsoft.Azure.Cosmos.PartitionKey partitionKey)> items, Microsoft.Azure.Cosmos.ReadManyRequestOptions readManyRequestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadManyItemsStreamAsync : System.Collections.Generic.IReadOnlyList<ValueTuple<string, Microsoft.Azure.Cosmos.PartitionKey>> * Microsoft.Azure.Cosmos.ReadManyRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage>
Public MustOverride Function ReadManyItemsStreamAsync (items As IReadOnlyList(Of ValueTuple(Of String, PartitionKey)), Optional readManyRequestOptions As ReadManyRequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResponseMessage)

参数

readManyRequestOptions
ReadManyRequestOptions

ReadMany 操作的请求选项

cancellationToken
CancellationToken

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

返回

包含 Task 的 , ResponseMessage 它包装 Stream 包含响应的 。

示例

IReadOnlyList<(string, PartitionKey)> itemList = new List<(string, PartitionKey)>
{
    ("Id1", new PartitionKey("pkValue1")),
    ("Id2", new PartitionKey("pkValue2")),
    ("Id3", new PartitionKey("pkValue3"))
};

using (ResponseMessage response = await this.Container.ReadManyItemsStreamAsync(itemList))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }

    //Read or do other operations with the stream
    using (StreamReader streamReader = new StreamReader(response.Content))
    {
        string content = streamReader.ReadToEndAsync();
    }

}

注解

ReadManyItemsStreamAsync(IReadOnlyList<ValueTuple<String,PartitionKey>>, ReadManyRequestOptions, CancellationToken) 与使用 IN 语句提取大量独立项的查询相比,在延迟方面执行得更好。

适用于