
Daniel S. answered 04/23/22
Software Engineer Specializing in .NET Core/5/6
This answer can be nontrivial, depending on certain parameters. If you are inserting 4000 rows, and each row consists of data that is reasonable in size (let's say 1kb in size), you can take advantage of Entity Framework's unit of work paradigm (where you perform multiple database operations and it is all or nothing). All you have to do is something like "context.table.Add(object)". The key here is that you have to call SaveChanges once and only once. If you are inserting 4,000 records and it is taking 10 minutes or more, I suspect you are calling SaveChanges after inserting each record, instead of inserting the records and then calling SaveChanges once.