bouh
bouh

Reputation: 536

How to access to the DBContext used in an EntityManager?

I insert/update a large amount of entities (~5000) during a process and this is taking a huge amount of time (it timeout on a 5 minutes transaction).

I read that by default the DBContext.AutoDetectChangesEnabled is set to ON and cause this kind of behavior (http://www.exsertus.be/2014/10/ef-bulk-performance/).

To my understanding, Devforce "kind of" encapsulate a DBContext within each EntityManager. Devforce use it's own implementation unless I define mine which I did. I would like to know how can I access it to be able to "play" with this property AutoDetectChangesEnabled.

Or are there any other solution to insert/update/delete large amount of entities with Devforce ?

Regards

Upvotes: 1

Views: 812

Answers (2)

Omar.Alani
Omar.Alani

Reputation: 4130

I have worked with this EF tool "https://www.nuget.org/packages/EFUtilities" and I got big performance enhancement with large inserts, as it uses bulk copy instead of normal insert per entity.

You can check the documentation of Github here.

I have used it with a 17,000 entities insert transaction and it finished it in a few seconds. Check this to get a better understanding and comparison with EF. http://blog.credera.com/technology-insights/microsoft-solutions/entity-framework-batch-operations-using-ef-utilities/

A sample of using the utility to insert a list of entities is like this:

using (var db = new YourDbContext())
{
    EFBatchOperation.For(db, db.BlogPosts).InsertAll(list);
}

Hope this helps.

Upvotes: 1

Kim Johnson
Kim Johnson

Reputation: 1227

Since you've defined your own DbContext you can alter this property setting in the DbContext constructor with Configuration.AutoDetectChangesEnabled = false;

However, I'm not sure how much this change will help. If your application is n-tier and you're trying to save ~5000 entities across the wire this will always be slow, and you'll also run into communication timeouts. Generally if you need to do any bulk operations DevForce isn't the optimal approach.

Upvotes: 0

Related Questions