Share via


DbContextOptionsBuilder<TContext>.EnableThreadSafetyChecks 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<TContext> EnableThreadSafetyChecks (bool checksEnabled = true);
override this.EnableThreadSafetyChecks : bool -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<'Context (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)>
Public Overridable Function EnableThreadSafetyChecks (Optional checksEnabled As Boolean = true) As DbContextOptionsBuilder(Of TContext)

Parameters

checksEnabled
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