ardalis/EFCore.Extensions

Add Extensions to Enable/Disable tracking on a DbContext

Aperta

#1 aperta il 6 ago 2019

 (0 commenti) (0 reazioni) (0 assegnatari)C# (8 fork)github user discovery
good first issue

Metriche repository

Star
 (44 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

If you want to force the dbContext to make a new db call instead of relying on its identity map, you can do so with this approach:

dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var fromDb = await dbContext. [whatever query]
dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;

Create extension methods that simply turn off tracking and then turn it back on that require less code than assigning to the QueryTrackingBehavior does.

Guida contributor