I have a MVC Action that imports data from a CSV file using EF. When I read a new record from CSV, I need to check if that record already exists including records that I have already imported before Saving, so I can update it instead of creating a new record.
The simple solution is to just SaveChanges()
after every dbContext.Entities.Add(newEntity)
call but I suspect that is not very efficient. It also means that I cannot rollback (easily) to prior to beginning the import. I.e. if any part of the import fails, I can avoid calling SaveChanges()
My question is: Can I search "Added" entities, then update them, before I call dbContext.SaveChanges()
once, at the end of my import routine?