title: Bulk insert with EF
body: <p>I need to insert some objects (about 4 million) in the database using C# and EF (using .NET 3.5). My method that adds the objects is in a for:</p>
  
  <pre><code> private DBModelContainer AddToContext(DBModelContainer db, tblMyTable item, int count)
          {
              db.AddTottblMyTable (item);
              if ((count % 10000== 0) || (count == this.toGenerate))
              {
                  try
                  {
                      db.SaveChanges();
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine(e.StackTrace);
                  }
              }
              return db;
          }
  </code></pre>
  
  <p>How to detach the added objects (of type tblMyTable) from the context object? I don't need them for a later use and when more than 300000 objects are added, the execution time between db saving ( db.SaveChanges()) increases considerably. </p>
  
  <p>Regards</p>