Bulk-Insert to MySQL in Entity-Framework Core

2019-04-28 05:17发布

问题:

I have a list consisting of ~10,000 objects (let's say of class Person) that I need to insert to a MySQL table. If I use the regular DbContext.SaveChanges(), it takes 60-70 seconds to issue, which I need to reduce drastically. I've found several extensions for bulk-insertions:

  • EF extensions (not free, so no option)
  • BulkExtensions (no MySQL, only SQL Server)
  • EFBulkInsert (no MySQL,only SQL Server) ...

Unfortunately, non seem to exist for MySQL databases. Does anybody know of one for MySQL? If not, could anyone give me an approach as to how I could make my own or adjust the aforementioned solutions? Thank you!

回答1:

Have you trying disabling traking inside the dbContext you may write:

ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;


回答2:

Fortunately it is available now for free:

EF6.BulkInsert.MySql 6.1.0.6 durch Vitor Ortuondo

BulkInsert.EF6.MySql 6.0.4 durch Kinshines