Reputation: 30388
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
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
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