Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Query Issue with using Any on DocumentDB for child collection

Using v1.8 .Net SDK

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) 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 is a GUID, but trying to query any property on the client object returns the same error.

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

like image 635
Chris Small Avatar asked Jul 08 '16 21:07

Chris Small


1 Answers

This query can be alternatively expessed using SelectMany + Where:

Sales.SelectMany(s => s.Clients.Where(c => c.ClientID == clientID).Select(c => s));  
like image 189
Aravind Krishna R. Avatar answered Sep 23 '22 04:09

Aravind Krishna R.