与 LINQ 一起使用的 OrderBy returns DOcumentDb 中没有行

OrderBy used with LINQ returns no rows in DOcumentDb

我一直在尝试在 LINQ 中使用 OrderBy 我已经更改了几个字段,但当我的文档出现在集合中时它总是 returns null(无行)。 这是我的简单查询-

        var rests = _client.CreateDocumentQuery<Restraunt>(_collectionUri)
                         .OrderBy(x => x.RestName); 

您必须创建一个索引策略,其中包含您在 order by 中使用的 属性 类型的范围索引(这里我假设是一个字符串)。

如果让默认策略,订单按return没有结果。

您需要这样的排序策略:

restrauntsCollection.IndexingPolicy.IncludedPaths.Add(
    new IncludedPath { 
        Path = "/RestName/?", 
        Indexes = new Collection<Index> { 
            new RangeIndex(DataType.String) { Precision = -1 } } 
        });

有关详细信息,请参阅此页面:https://azure.microsoft.com/en-us/documentation/articles/documentdb-orderby/

希望对您有所帮助