SQL Server Timeout scenarios with Large Batch Inserts Using Entity Framework Core
I'm trying to implement I've looked through the documentation and I'm still confused about I'm working on a personal project and I'm working with a 'Timeout expired' behavior when attempting to insert a large batch of records into a SQL Server database using Entity Framework Core (version 5.0)... My current setup involves a `List<MyEntity>` that Iβm trying to save using the `AddRange` method, but it seems to hang or time out after the first few entries. I've set the command timeout to 180 seconds in my `DbContext` configuration, but it doesn't appear to be having any effect. Hereβs a snippet of the code I'm using: ```csharp var myEntities = new List<MyEntity>(); for (int i = 0; i < 10000; i++) { myEntities.Add(new MyEntity { Name = "Entity " + i }); } using (var context = new MyDbContext()) { context.Database.SetCommandTimeout(180); context.MyEntities.AddRange(myEntities); context.SaveChanges(); } ``` I've also tried breaking the inserts into smaller batches of 1000, but I still experience the same timeout scenario. Additionally, I checked the SQL Server logs and found this behavior message: `A transport-level behavior has occurred when sending the request to the server.` I am using SQL Server 2019 and I'm running this on a local development environment with sufficient resources. Could this be an scenario with how EF Core is managing the transaction, or perhaps a question with my SQL Server configuration? I would appreciate any insights or recommendations for optimizing large insert operations with EF Core. This is part of a larger application I'm building. I'm working on a service that needs to handle this. Am I missing something obvious? The project is a web app built with C#. Am I approaching this the right way?