我编写了以下代码来从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();上显示以下错误

{"跨分区查询是必需的,但已禁用.请设置

请帮帮我.

推荐答案

您应该使用带有FeedOptions对象的CreateDocumentQuery方法作为参数,这个类有一个名为EnableCrossPartitionQueryx-ms-documentdb-query-enablecrosspartition属性.

请点击链接https://msdn.microsoft.com/library/en-us/Dn850285.aspx

例子:

你应该

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

Asp.net相关问答推荐

AJAX返回未定义、失败

JWT 和 Google 在 Razor 页面中进行身份验证和授权

InvalidOperationException:在程序集上找不到UserSecretsIdAttribute

判断 asp.net mvc 4 应用程序中的 ssl 协议、密码和其他属性

更改 GridView 中列的标题文本

为什么 ASP.NET Identity 2.0 使用 GUID/字符串作为用户 ID?

如何将 Castle Windsor 与 ASP.Net Web 表单一起使用?

'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册.

发布发布事件

aspx 文件中的 if 语句

在 ASP.NET 中将虚拟路径转换为实际 Web 路径

从 IFrame 重定向父页面

如何忽略身份框架的魔力,只使用 OWIN 身份验证中间件来获取我寻求的声明?

使用 .NET 连接到 AS400

如何使用 encodeURIComponent() 解码在 JS 中编码的 HTML?

使 WCF Web 服务与 GET 请求一起工作

ASP.net 网站中的 C# 密码文本框

将字符串转换为时间

获取 POST 变量

新的 csproj 文件 struct 可以与 ASP.NET Framework 项目一起使用吗?