[英]Addition of OrderBy clause to a DocumentDB LINQ query breaks it (C#)
I am using the Azure Documents SDK in C# in .net core 1.0.1 with LINQ to abstract a simple Fetch method that takes lambdas as parameters. 我正在通过LINQ在.net core 1.0.1的C#中使用Azure文档SDK来抽象一个简单的Fetch方法,该方法将lambda作为参数。 It works fine EXCEPT when I add an
ORDER BY
clause – although I have no idea why. 当我添加
ORDER BY
子句时,它可以正常工作,尽管我不知道为什么。 Here's the method: 方法如下:
public async Task<IEnumerable<T>> Fetch<R>(Expression<Func<T, bool>> predicate, Expression<Func<T, R>> orderby, int count)
{
var results = new List<T>();
var collectionLink = UriFactory.CreateDocumentCollectionUri(_config.Database, _collectionId);
// This works
//var document = _client.CreateDocumentQuery<T>(collectionLink).Where(predicate).Take(count).AsDocumentQuery();
// This ** DOESN'T ** work
var document = _client.CreateDocumentQuery<T>(collectionLink).Where(predicate).OrderBy(orderby).Take(count).AsDocumentQuery();
var feedResponse = await document.ExecuteNextAsync<T>();
results.AddRange(feedResponse.AsEnumerable<T>());
return results;
}
With the addition of the .OrderBy()
method, I get 0 results returned. 加上
.OrderBy()
方法,我得到了0个返回的结果。 With its removal, I get the expected 10 (albeit in insertion order). 删除后,我得到了预期的10(尽管按插入顺序)。 In looking at the SQL being generated by the
.AsDocumentQuery()
method, I can't see anything obviously wrong, so I'm at a bit of a loss as to why. 在查看由
.AsDocumentQuery()
方法生成的SQL时,我看不到任何明显错误的内容,因此我对其中的原因有些.AsDocumentQuery()
。 For completeness, here's an example of its' usage... 为了完整起见,下面是其用法的示例...
var result = data.Fetch(f => f.Firstname.Contains("i"), x => x.Firstname, 10);
... and the query that it produces: ...及其产生的查询:
SELECT TOP 10 * FROM root WHERE CONTAINS(root["Firstname"], "i") ORDER BY root["Firstname"] ASC
Is this an SDK bug or am I missing something obvious? 这是SDK错误还是我遗漏了一些明显的东西?
Thanks! 谢谢!
Whenever I see strange behavior like this it's usually because you have a hash index (the default) as opposed to a range index on that field. 每当我看到这样的奇怪行为时,通常是因为您具有哈希索引(默认值),而不是该字段上的范围索引。 Check the indexing policy for the collection.
检查集合的索引策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.