Base solution for your next web application
Open Closed

Best way to do bulk insert of 10,000 rows! #1272


User avatar
0
mengvisal created
Support Team

Hi,

What is the best way to do bulk insert of 10,000 rows? I cannot find "AddRange" or "BulkInsert" extension of entity framework in ASP.NET Zero generic repository. When i try to do single insert for 10,000 rows and then it times out. My current method is to call save change method or create new unit of work for every 1000 rows. So what is your suggestion?

Best,

Visal


5 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    EF does not support it by default, but there are some 3rd part libraries, you can searh for them.

    But, if you don't want to use them, you can increase timeout value. Add [UnitOfWork] attribute to your app service method and set timeout to a high value. Also, Use single UOW, not multi. And don't explicitly call savechanges since it's better to save all in once. 10,000 is not a big count, it should work if there is no db related performance issue.

  • User Avatar
    0
    mengvisal created
    Support Team

    I saw people talking about bulkinsert extension but I am wondering how or where I can apply it with ASP.net Zero since I do not explicitly instatiate the context? I use unit of work and repository as illustrated in the asp.net zero examples.

  • User Avatar
    0
    hikalkan created
    Support Team

    If you need to access to DbContext, you should create a custom repository method. Example and document: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/EntityFramework-Integration#DocCustomRepositoryMethods">http://www.aspnetboilerplate.com/Pages/ ... oryMethods</a> Please read this.

  • User Avatar
    0
    mengvisal created
    Support Team

    I try to extend timeout and save all 20,000 records at once but it seems much slower than saving or instantiating new unit of work for every 1,000 records.

  • User Avatar
    0
    hikalkan created
    Support Team

    OK, then we definitely suggest you to use some batch insert library.