Asynchronously returns the only element of a sequence, and throws an InvalidOperationException exception if there is not exactly one element in the sequence.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@linhub15 We can document the type of exception thrown, but I'm curious as to why it matters? It is not intended that this exception be expected and caught as a normal part of an application running. It is intended to indicate that there isn't a single element and therefore calling this method was an invalid operation.
I wasn't sure if other Exceptions would bubble up from SingleAsync() so
Rather than:
catch (Exception e) { ... }
I wanted to use:
catch (InvalidOperationException e) { ... }
So I could throw my custom Exception EntityNotFoundException
I think I used this method incorrectly...
In hind sight I should have used SingleDefaultOrAsync to check for default, then throw my Exception.
Team notes: after discussing this we think it would be more helpful to:
Duplicate of #17692
Most helpful comment
Team notes: after discussing this we think it would be more helpful to: