Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:49:04+00:00 2026-06-01T17:49:04+00:00

When using DbContext in a database-first scenario I found out that adding and deleting

  • 0

When using DbContext in a database-first scenario I found out that adding and deleting entities is very slow compared to ObjectContext. If adding 2000 entities and saving the changes at the end, DbContext is 3 to 5 times slower than ObjectContext (btw.: I know that adding a large amount of entities would be better using SqlBulkCopy but that’s not the point). If saving changes after each addition DbContext is still nearly two times slower. When it comes to deletion it even gets worse: When saving at the end of all entity removals, DbContext is around 18 times slower than ObjectContext.

I took my highly developed test application I use to compare database access technologies and a small console application to double check. Both showed bad results for adding and deleting entities using DbContext. Here are the results of the console application:

Inserting 2000 entities via DbContext saving changes at the end: 2164ms
Inserting 2000 entities via ObjectContext saving changes at the end: 457ms
Inserting 2000 entities via DbContext saving changes after each object addition: 8420ms
Inserting 2000 entities via ObjectContext saving changes after each object adding: 4857ms
Inserting 2000 entities via DbContext using a new DbContext for each object addition: 4018ms
Deleting 2000 entities via DbContext saving changes at the end: 4794ms
Deleting 2000 entities via ObjectContext saving changes at the end: 261ms
Deleting 2000 entities via DbContext saving changes after each object deletion: 25536ms
Deleting 2000 entities via ObjectContext saving changes after each object deletion: 2110ms

I tried using EF 4.3 in VC 2010 and EF 5.0 Beta 2 in VS 11 with nearly same results. I used the T4 templates provided by the “EF 4.x POCO Entity Generator for C#”, the “EF 4.x DbContext Generator for C#” and the “EF 5.x DbContext Generator for C#”.

What could be wrong? According to the test results I would never use DbContext in an application that has to add or delete entities (what makes DbContext unfortunately unusable for me).

I put the console test applications on my web server: EF 4.3 DbContext Test, EF 5.0 DbContext Test

Any ideas/corrections are appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:49:05+00:00Added an answer on June 1, 2026 at 5:49 pm

    Try to add this to your DbContext tests:

    dbContext.Configuration.AutoDetectChangesEnabled = false;
    
    // Now do all your changes
    
    dbContext.ChangeTracker.DetectChanges();
    dbContext.SaveChanges();
    

    and try to run your tests again.

    There was some architectural change in DbContext API which checks changes in entities every time you Add, Attach or Delete anything from the context. In ObjectContext API this detection run only when you triggered SaveChanges. It is better solution for most common scenarios but it requires special handling for mass data processing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using chrome 15 on osx 10.6.8 When adding event listeners, I've found that putting
NOTE: I'm using EF 4.2 with Database First Method and DbContext. This is NOT
I'm using EF 4.2 (database-first) with the DBContext T4 templates to create my POCO
I am working on an application that uses EF 4.2 and database-first development, using
I have an EF code-first generated database. Data manipulation is done using DbContext .
I have a problem in Entity-Framework, using Code-First, that I couldn't solve. Having entities
I've recently started using Entity Framework migrations and noticed that the database name is
I'm using database first approach to create a model with entity framework. In VS2010
I'm using ASP.NET MVC 3.0 Database First approach with EF 4.x. Models are generated
I'm using Entity Framework 4.1 Code First and I have a table that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.