在DocumentDB上使用Any进行子集合的LINQ查询问题 [英] LINQ Query Issue with using Any on DocumentDB for child collection

查看:54
本文介绍了在DocumentDB上使用Any进行子集合的LINQ查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用v1.8 .Net SDK

Using v1.8 .Net SDK

尝试退货,其中销售客户数组包含我要寻找的客户ID.

Trying return Sales where the Sale client array contains the Client ID I’m looking for.

Sales.Where(sale => sale.Clients.Any(c => c.ClientId == clientID));

返回错误 空对象必须具有一个值."

Returns Error "Nullable object must have a value."

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) 在System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task 1.get_Result() 在Microsoft.Azure.Documents.Linq.DocumentQuery 1.GetEnumerator() at System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1源)

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at Microsoft.Azure.Documents.Linq.DocumentQuery1.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

ClientID是一个GUID,但是尝试查询客户端对象上的任何属性都会返回相同的错误.

ClientID is a GUID, but trying to query any property on the client object returns the same error.

如果我对相同的数据运行相同的查询,但仅使用List集合(即不使用DocumentDB),那么一切都很好.

If I run the same query on the same data but just using a List collection (i.e. not using DocumentDB) then all is fine.

任何建议都值得赞赏. 谢谢

Any advice appreciated. Thanks

推荐答案

可以使用SelectMany +其中:

This query can be alternatively expessed using SelectMany + Where:

Sales.SelectMany(s => s.Clients.Where(c => c.ClientID == clientID).Select(c => s));  

这篇关于在DocumentDB上使用Any进行子集合的LINQ查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆