gpt4 book ai didi

c# - .NET - c# - 需要跨分区查询,但禁用了 DocumentDB 数据访问问题

转载 作者:IT王子 更新时间:2023-10-29 04:47:47 35 4
gpt4 key购买 nike

我编写了以下代码来从 DocumentDB 中获取记录

private static void QueryDocuments1(DocumentClient client)
{

IQueryable<SearchInput> queryable =
client.CreateDocumentQuery<SearchInput>(UriFactory.CreateDocumentCollectionUri(DocumentDBName, DocumentDBCollectionName))
.Where(x => x.Receiver == "8907180");
List<SearchInput> posts = queryable.ToList();
}

它在代码行 List<SearchInput> posts = queryable.ToList(); 上显示以下错误

{"Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.\r\nActivityId: xxxxxx-xxxx-xxx-xxx-xxxxxxx"}

请帮助我...

最佳答案

您应该使用 CreateDocumentQuery 方法并将 FeedOptions 对象作为参数,此类具有 x-ms-documentdb-query-enablecrosspartition 的属性> 调用了 EnableCrossPartitionQuery

请点击链接 https://msdn.microsoft.com/library/en-us/Dn850285.aspx对于休息 https://learn.microsoft.com/en-us/rest/api/documentdb/querying-documentdb-resources-using-the-rest-api

示例:

你应该有

 var option = new FeedOptions { EnableCrossPartitionQuery = true };
IQueryable<SearchInput> queryable = client.CreateDocumentQuery<SearchInput>
(UriFactory.CreateDocumentCollectionUri(DocumentDBName,
DocumentDBCollectionName), option ) .Where(x => x.Receiver == "8907180");

关于c# - .NET - c# - 需要跨分区查询,但禁用了 DocumentDB 数据访问问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46170004/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com