Ehsan Ghanbari

Experience, DotNet, Solutions

Introducing Z.bulkOperation

Today I was tackling with a problem. It was about inserting and updating 200000 records of data. I just wanted to find a solution rather than writing Store Procedure. I just searched on the web and found a library named Z.BulkOperation

I dare say I had never seen handling this amount of data nicely in application level without even using a line of SQL code, it's awesome!

Fire up visual studio and a simple console or MVC application and install the package via:

PM> Install-Package Z.BulkOperations

PM> Install-Package Z.EntityFramework.Extensions

And run the following code sample and see the result:

   public ActionResult Insert()

        {

            DbContextClass contextClass = new DbContextClass();



            var userList = new List<User>();



            for (int i = 0; i < 500000; i++)

            {

                userList.Add(new User

                {

                    Email = "[email protected]",

                    Id = Guid.NewGuid(),

                    Password = "123",

                    Username = "ehsan"

                });

            }



            contextClass.BulkInsert(userList);



            return View();

        }

The insert operation for 500000 of records would be 29.648 ms in my machine! And just for update operation for the same data:

   public ActionResult Update()

        {

            DbContextClass contextClass = new DbContextClass();



            var userList = new List<User>();



            var users = contextClass.Users.ToList();



            foreach (var user in users)

            {

                user.Email = "[email protected]";               

                user.Password = "12343242";

                user.Username = "ehsanghanbari";



                userList.Add(user);

            }



            contextClass.BulkUpdate(userList);



            return View();

        }

It resulted in 28.232ms and for delete operation:

        public ActionResult Delete()

        {

            DbContextClass contextClass = new DbContextClass();



            var userList = new List<User>();



            var users = contextClass.Users.ToList();



            contextClass.BulkDelete(users);



            return View();

        }

It elapsed 14.324 ms.

I really enjoyed and hope you enjoy as well ;)

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
using Log4net in asp.net MVC4
How to use PagedList In asp.net MVC
Redis as a cache server
Domain driven design VS model driven architecture
What's the DDD-lite?
Multiple submit buttons in asp.net MVC
comments powered by Disqus