Bulk-Insert to MySQL in Entity-Framework Core

老子叫甜甜 提交于 2019-12-07 02:46:46

问题


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



来源:https://stackoverflow.com/questions/44205850/bulk-insert-to-mysql-in-entity-framework-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!