我想从 Cosmos DB 检索一项,肯定有比我在这里所做的更好的方法。
我尝试过其他命令,但这似乎确实有效。
public async Task<ToDoItem> GetAsync(string id)
{
FeedIterator<ToDoItem> results = container.GetItemQueryIterator<ToDoItem>("select top 1 * from Items i where i.id = '" + id + "'");
FeedResponse<ToDoItem> item = await results.ReadNextAsync();
return item.Resource.FirstOrDefault();
}
我希望能够通过在 服务器并且不会强迫我查看一组项目。
query
,
using (ResponseMessage responseMessage = await container.ReadItemStreamAsync(
partitionKey: new PartitionKey("Account1"),
id: "SalesOrder1"))
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();
}
}
}