Azure cosmosdb 我应该如何使用v3api从Cosmos获得一个项目?

Azure cosmosdb 我应该如何使用v3api从Cosmos获得一个项目?,azure-cosmosdb,azure-cosmosdb-sqlapi,cosmos,Azure Cosmosdb,Azure Cosmosdb Sqlapi,Cosmos,我想从Cosmos DB中检索一个项目,肯定有比我在这里做的更好的方法 我尝试过其他命令,但这似乎确实有效 公共异步任务GetAsync(字符串id) { FeedIterator results=container.GetItemQueryIterator(“从项目i中选择前1个*,其中i.id='“+id+””); FeedResponse项=等待结果。ReadNextAsync(); 返回item.Resource.FirstOrDefault(); } 我希望能够用一行在 服务器,不会

我想从Cosmos DB中检索一个项目,肯定有比我在这里做的更好的方法

我尝试过其他命令,但这似乎确实有效

公共异步任务GetAsync(字符串id) { FeedIterator results=container.GetItemQueryIterator(“从项目i中选择前1个*,其中i.id='“+id+””); FeedResponse项=等待结果。ReadNextAsync(); 返回item.Resource.FirstOrDefault(); } 我希望能够用一行在
服务器,不会强迫我查看一组项目。

以下是一个从官方文件到


SDK仍在开发中-这可能有助于:

using (ResponseMessage response = await _container.ReadItemStreamAsync(id: pageId, partitionKey: partitionKey))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
    }

    await using (Stream stream = response.Content)
    {
        using (var streamReader = new StreamReader(stream))
        {
            string content = streamReader.ReadToEnd();
        }
    }
}

container.ReadItem…
操作用于点读取。
using (ResponseMessage response = await _container.ReadItemStreamAsync(id: pageId, partitionKey: partitionKey))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
    }

    await using (Stream stream = response.Content)
    {
        using (var streamReader = new StreamReader(stream))
        {
            string content = streamReader.ReadToEnd();
        }
    }
}