与LINQ一起使用的Order在DOcumentDb中不返回任何行

时间:2016-03-31 05:13:26

标签: linq sql-order-by azure-cosmosdb

我一直在尝试在LINQ中使用OrderBy我已经更改了几个字段,但它总是返回null(没有行),而我的文档存在于集合中。 这是我的简单查询 -

  DialogResult confirm = MessageBox.Show("confirm Exit?", "exit", MessageBoxButtons.YesNo);
            if (confirm==DialogResult.Yes)
                Application.Restart();
            else
            {
                //do some thing
            }

1 个答案:

答案 0 :(得分:0)

您必须创建一个索引策略,其中包含您在订单中使用的属性类型的范围索引(此处我假设为字符串)。

如果您使用默认策略,则按顺序返回无结果。

您需要这样的排序策略:

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/

希望这有帮助