Note that there are some explanatory texts on larger screens.

plurals
  1. PODbContext is very slow when adding and deleting
    primarykey
    data
    text
    <p>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. </p> <p>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:</p> <pre><code>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 </code></pre> <p>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#".</p> <p>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).</p> <p>I put the console test applications on my web server: <a href="http://www.juergen-bayer.net/downloads/ef4.3DbContextTest.zip" rel="noreferrer">EF 4.3 DbContext Test</a>, <a href="http://www.juergen-bayer.net/downloads/ef5.0DbContextTest.zip" rel="noreferrer">EF 5.0 DbContext Test</a></p> <p>Any ideas/corrections are appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload