Cosmos DB linq查询返回子文档上的“ where any”

时间:2018-09-21 08:21:51

标签: azure-cosmosdb azure-cosmosdb-sqlapi

给出此Cosmos DB文档规范...

{
  "Id": "123",
  "Name": "Customer",
  "Products": [
  {
      "Name": "ProdA"
  },
  {
      "Name": "ProdX"
  }],
}

是否可以以from..select..where格式构造一个c#linq查询,从而使我们能够使用ProdX查找所有客户?

不支持常规的.Any()方法。

我可以使用SelectMany() Where() Select()来达到同样的效果,但是我很想知道是否可以使用from..select..where方法来实现这一点。

我们发现此格式更干净,更易于阅读和维护。

所有正式文档似乎都只引用Products[0],后者仅发现以ProdX作为其第一款产品的客户。无论ProdX在阵列中的什么位置,我们都需要找到客户。

我希望使用以下方式实现此查询:

 var customersWithProdX = 
     from customer in client.CreateDocumentQuery<Customer>(UriFactory.CreateDocumentCollectionUri("CustomersDb", "Customers"))
     from product in customer.Products
     where product.Name == "ProdX"
     select customer;

但不幸的是,我收到以下异常:

Message "Incorrect number of arguments for method 'SelectMany'. Expected '2' but received '3'., documentdb-dotnet-sdk/2.0.0 Host/32-bit MicrosoftWindowsNT/6.2.9200.0"  

0 个答案:

没有答案