user2011126
user2011126

Reputation: 71

yourContext.Configuration not available

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

Answers (2)

Aaron Winters
Aaron Winters

Reputation: 11

I was using EF Core and found AutoDetectChangesEnabled under ChangeTracker:

context.ChangeTracker.AutoDetectChangesEnabled = false

Upvotes: 1

pravprab
pravprab

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

Related Questions