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)
-
0
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.
-
0
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.
-
0
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.
-
0
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.
-
0
OK, then we definitely suggest you to use some batch insert library.