Sam
Sam

Reputation: 30388

Cosmos DB read call

I'm making a call to Azure Cosmos DB where I know the data I'm querying does NOT exist.

I was expecting to get a null value but instead I'm getting:

Enumeration yielded no results

enter image description here

How do I test whether I received a value or not? I was testing for null which doesn't work because the outcome is not null.

My code looks something like this:

var result = await _client.ReadQuery<myObject>(AccountsCollection, sql, pa);
if(result == null)
   return null;

Upvotes: 0

Views: 234

Answers (1)

maccettura
maccettura

Reputation: 10818

Instead of just checking on result == null you should use the LINQ extension method .Any() to see if there are any items that match a condition (in your case the condition is just anything existing in the collection):

if(result == null || !result.Any())
{
    return null;
}

Upvotes: 1

Related Questions