Base solution for your next web application

Activities of "andonisan"

Answer

Hi,

You´re right about adding a bulk insert method only disabling autodetectchanges.

i added to my project other open source project

<a class="postlink" href="https://efbulkinsert.codeplex.com/">https://efbulkinsert.codeplex.com/</a>

Now the performance is awesome for bulk inserting,

this example is in my EnityFramework project Repositories

public  Task SetList(List<Entity> input)
        {
           

            return Task.Run(() =>
              {
                  using (var transactionScope = new TransactionScope())
                  {

                      Context.BulkInsert(input);
                      Context.SaveChanges();
                      transactionScope.Complete();

                  }
              }
            );
        }

Thanks a lot

Question

Hello,

First thank you for your great work .

I have a doubt about which is the best way to bulk insert with the repository pattern, because when i have to insert 500 rows it takes a lot of time.

I have tried disabling AutoDetectChangesEnabled but the performance still very bad

Maybe IRepository colud be extended to insertRange for this kind of insertions?

using (var unitOfWork = _unitOfWorkManager.Begin())
                  {

                      Context.Configuration.AutoDetectChangesEnabled = false;
                      foreach (var element in list)
                      {
                          Insert(element);
                      }

                      Context.Configuration.AutoDetectChangesEnabled = true;

                      unitOfWork.Complete();
                  }
Showing 1 to 2 of 2 entries