'Should I check a CancellationToken before calling EF or allow EF to check it itself?

I am adding CancellationTokens into my .NET Core + EF application.

Should I check for cancellation before calling EF, or should I pass the cancellation token to EF and trust that EF will check it itself before starting any work?

"Trust EF to check" approach:

...

_context.Users.ToListAsync(cancellationToken);

...

"Check myself" approach:

...

cancellationToken.ThrowIfCancellationRequested();
_context.Users.ToListAsync(cancellationToken);

...

Which approach is recommended?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source