I have a context to a read-only database for reporting and I am writing lots of code, like this:
using (var context = new ReportingContext())
{
var reportXQuery = context.ReportX.AsNoTracking();
// Do stuff here with query...
}
Is there a way to set the AsNoTracking
bit so that just new
ing up the ReportingContext
above would automatically use AsNoTracking
instead of needing to remember to explicitly call it every query?
Try changing your context constructor to this:
public ReportingContext()
{
this.Configuration.AutoDetectChangesEnabled = false;
}
EDIT:
This will after all not help you, as stated on Arthur's blog, it is usable only in particular scenarios: