Entity Framework Bulk Insert Throws KeyNotFoundException error

前端 未结 3 1019
借酒劲吻你
借酒劲吻你 2021-01-17 16:21

I am using EF6 and due to the low speed of AddRange() method I need to use BulkInsert. So I added the NuGet package of BulkInsert for

3条回答
  •  悲&欢浪女
    2021-01-17 17:04

    The "BulkInsert" library is very fast but not very flexible and unsupported.

    It doesn't support all type of inheritance (TPC, TPT) and has some issue with column mapping.

    The issue you got is for one of these reasons.

    Disclaimer: I'm the owner of the project Entity Framework Extensions

    This library is the ultimate library for performance and allow to:

    • BulkSaveChanges
    • BulkInsert
    • BulkUpdate
    • BulkDelete
    • BulkMerge

    All inheritance and association are supported.

    Example:

    using (var db = new Entities(myConnectionString)
    {
        db.BulkInsert(contactsToInsert);
    }
    
    // BulkSaveChanges is slower than BulkInsert but way faster then SaveChanges
    using (var db = new Entities(myConnectionString))
    {
        db.Contacts.AddRange(contactsToInsert);
        db.BulkSaveChanges();
    }
    

提交回复
热议问题