【发布时间】:2022-06-15 21:58:38
【问题描述】:
我正在尝试从名为 Articles 的容器中获取单个文章项目,它具有分区键 /slug
public async Task<Article> GetArticle(string slug)
{
try
{
var response = await _container.ReadItemAsync<Article>(slug, new PartitionKey(slug));
return response.Resource;
}
catch (CosmosException) //For handling item not found and other exceptions
{
return null;
}
}
This 是我获取示例代码的链接。
在我的情况下,它返回No Content,但我确信有一篇文章与那个蛞蝓有关。
我想知道问题是否与我的容器或查询有关?!
【问题讨论】:
-
它使用 /id=slug 和 /slug=slug 搜索项目。你必须做一个查询。例如。 GetItemQueryIterator
-
查询返回一个数组,对吗?
-
你的
Article类型是什么样的?