1 year ago

#353562

test-img

Frammo

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?

c#

.net

entity-framework

cancellation-token

0 Answers

Your Answer

Accepted video resources