Improve data Insertion performance in entity framework || Fatest way to insert huge data in entity framework C#.NET

Introduction 
In this article i will talk about how to improve performance when you want to insert records using entity framework, and how you can add and use bulk insert extension in visual studio.

The basic idea is to reduce the hits on database server as possible, the worst case is to insert each record in database hit.



Practical Performance testing :

I'm prepared simple practical test for entity framework performance for inserting data.And i take five methods of insert in test comparison  as following :


  • Bulk Insert Extension.(i will explain how to install it from nuget)
  • AddRange method.
  • Add method with one SaveChanges().
  • Add method with one SaveChange() for each 100 record.
  • Add method with SaveChanges() for each record.


Test Results :




Bulk Insert Extension Installation
As we notice , bulk insert is the faster method for insert data especially huge data in entity framework, you can install this great extension using visual studio nuget,
type in search box : Bulk Insert or refer to codeplex


After install it you need to import it in your class  :
using EntityFramework.BulkInsert.Extensions;
And simple you can call it :
dataContext.BulkInsert(ListOfRecordsToInsert);

Entity Framework Performance tips from msdn :
https://msdn.microsoft.com/en-us/data/hh949853.aspx

Hope that this article is helpful,

Comments

Popular posts from this blog

How to remove (.aspx) from ASP.NET web forms page url using Friendly URL package.

ASP.NET MVC - Load Partial View using ajax with progress indicator - Visual Studio 2013 MVC 5

Create (post) JIRA ticket (Issue) with rest API using C# ASP.NET