Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Context BulkSaveChanges #4200


User avatar
0
pankajmathur created

Hi,

I have written a function in the <MyApplication>RepositoryBase class that takes List of entity (List<Product> NewProducts) as input parameter. And following is the code of the function. Essentially, I am trying to bulkinsert products in the database. But in the last line of the code (i.e. Context.BulkSaveChanges();), it throws the following error: Exception: KeyNotFoundException Message: The given key was not present in the dictionary.

            Context.ChangeTracker.AutoDetectChangesEnabled = false;
            Context.Set&lt;Product&gt;().AddRange(NewProducts);
            Context.ChangeTracker.DetectChanges();
            Context.BulkSaveChanges();

Any idea what could be the reason and how to resolve this?

Regards, Mahendra


4 Answer(s)
  • User Avatar
    0
    pankajmathur created

    Hi,

    Please don't bother on my above issue. It has been fixed now...

  • User Avatar
    0
    aaron created
    Support Team

    Thanks for letting us know!

    In case anyone has the same issue, upgrade Z.EntityFramework.Extensions.EFCore to v2.0.8. Resolved here: https://github.com/zzzprojects/EntityFramework-Extensions/issues/63

  • User Avatar
    0
    20summers created

    Hi I would also like to implement Z.EntityFramework.Extensions.EFCore

    Can you explain how to use it. I have installed the nuget in the Application section

    How do I user it?

    I would like to update a bool to true on the following:

    var timesheets = _timesheetsDetailRepository.GetAll() .Where(e => e.TimesheetId == input.Id);

  • User Avatar
    0
    aaron created
    Support Team
    var context = _timesheetsDetailRepository.GetDbContext();
    context.BulkUpdate(timesheets);
    

    https://entityframework-extensions.net/bulk-update