Share via


DbContextOptionsBuilder.EnableThreadSafetyChecks(Boolean) Method

Definition

Disables concurrency detection, which detects many cases of erroneous concurrent usage of a DbContext instance and causes an informative exception to be thrown. This provides a minor performance improvement, but if a DbContext instance is used concurrently, the behavior will be undefined and the program may fail in unpredictable ways.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder EnableThreadSafetyChecks (bool enableChecks = true);
abstract member EnableThreadSafetyChecks : bool -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.EnableThreadSafetyChecks : bool -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function EnableThreadSafetyChecks (Optional enableChecks As Boolean = true) As DbContextOptionsBuilder

Parameters

enableChecks
Boolean

Returns

The same builder instance so that multiple calls can be chained.

Remarks

Only disable concurrency detection after confirming that the performance gains are considerable, and the application has been thoroughly tested against concurrency bugs.

Note that if the application is setting the internal service provider through a call to UseInternalServiceProvider(IServiceProvider), then this option must configured the same way for all uses of that service provider. Consider instead not calling UseInternalServiceProvider(IServiceProvider) so that EF will manage the service providers and can create new instances as required.

See Using DbContextOptions for more information and examples.

Applies to