查询表达式无效的cosmosdb [英] Query expression is invalid cosmosdb
问题描述
我正在尝试在cosmosdb中使用groupby并通过以下查询进行查询,
I am trying to query using groupby in cosmosdb with the following query,
var result = client.CreateDocumentQuery<Login>(documentUri)
.Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
.GroupBy(t => t._ts);
它会引发以下错误
DocumentQueryException:查询表达式无效,表达式 https://documents.azure.com/dbs/colls/test.Where( i =>((((i.logevent == 成功")AndAlso(i._ts> 1517405472))AndAlso(i._ts< = 1518010272))).不支持GroupBy(t => t._ts).支持的 表达式是"Queryable.Where","Queryable.Select"和 'Queryable.SelectMany
DocumentQueryException: Query expression is invalid, expression https://documents.azure.com/dbs/colls/test.Where(i => (((i.logevent == "Success") AndAlso (i._ts > 1517405472)) AndAlso (i._ts <= 1518010272))).GroupBy(t => t._ts) is unsupported. Supported expressions are 'Queryable.Where', 'Queryable.Select' & 'Queryable.SelectMany
Cosmos DB LINQ提供程序当前不支持
推荐答案
GroupBy.您必须使用AsEnumerable来实现where子句的结果,然后对对象使用LINQ来执行Group By.
GroupBy is not currently supported by the Cosmos DB LINQ provider. You have to materialize the results of the where clause using AsEnumerable, then perform Group By using LINQ on objects.
var result = client.CreateDocumentQuery<Login>(documentUri)
.Where(i => i.logevent == "Success" && i._ts > 1517405472 && i._ts <= 1518010272)
.AsEnumerable()
.GroupBy(t => t._ts);
注意:您应该将尽可能多的查询谓词下推到服务器.换句话说,Where子句应位于AsEnumerable的前面.
Note: you should push down as much of the query predicates to the server as possible. In other words, the Where clause should be in front of the AsEnumerable.
这篇关于查询表达式无效的cosmosdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!