Reputation: 71
On an earlier post, I read about setting:
yourContext.Configuration.AutoDetectChangesEnabled = false;
yourContext.Configuration.ValidateOnSaveEnabled = false;
To improve bulk insert performance. I am using Entity Framework 5.0, but can not find the yourContext.Configuration
object. When I select my context, I only see ContextOptions
, but not Configuration. Am I missing something?
Upvotes: 3
Views: 2501
Reputation: 11
I was using EF Core and found AutoDetectChangesEnabled
under ChangeTracker
:
context.ChangeTracker.AutoDetectChangesEnabled = false
Upvotes: 1
Reputation: 2293
The recommended way to work with context is to define a class that derives from DbContext . Its an abstract of your database. And exposes DbSet properties that represent collections of the specified entities in the context.
For example :
using System.Data.Entity;
public class ProductContext : DbContext
{
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
}
Then you can do like this
using (var context = new ProductContext())
{
context.Configuration.AutoDetectChangesEnabled = false;
}
Upvotes: 0