给出此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"