.NET EF Core Plus BulkInsert 需要永远
.NET EF Core Plus BulkInsert takes forever
我有一个 WebApi,我尝试在其中插入来自 EF Core Plus (https://www.nuget.org/packages/Z.EntityFramework.Plus.EFCore/) 的 AppDbContext.BulkInsertAsync(...),我的数据库中有 15.000 多条记录。
不幸的是,这需要很长时间,而且当我尝试只插入 10 条记录时,这样做需要 15-20 秒:
AppDbContext.BulkInsert(myEntities.Take(10));
但我需要实现以下目标:
// Store the actual Trucks
List<MyEntity> myEntities = new List<MyEntity>(); // <-- Contains more than 15.000 objects
AppDbContext.BulkInsert(newTruckCosts); // <-- This takes forever...
MyEntity 有 19 个属性,有 5 个指向其他实体的外键。
我确实尝试了很多,但我真的被困在这里,尤其是对于 15.000 多条记录,它需要很长时间。
会不会因为我的实体有几个外键引用了我数据库中的其他实体,所以花了这么长时间?
此外,不知道这是否重要,我在 Azure(基本层)、.NET Core 和 EntityFramework Core 中使用 SQL 数据库。
因此,通过将 Azure SQL 数据库从基本层升级到标准 S1 层,实现了重大改进。
使用 Basic Tier 只需花费很长时间,现在使用 Standard S1 Tier 大约需要 15 秒,这对我来说完全没问题。
我有一个 WebApi,我尝试在其中插入来自 EF Core Plus (https://www.nuget.org/packages/Z.EntityFramework.Plus.EFCore/) 的 AppDbContext.BulkInsertAsync(...),我的数据库中有 15.000 多条记录。
不幸的是,这需要很长时间,而且当我尝试只插入 10 条记录时,这样做需要 15-20 秒:
AppDbContext.BulkInsert(myEntities.Take(10));
但我需要实现以下目标:
// Store the actual Trucks
List<MyEntity> myEntities = new List<MyEntity>(); // <-- Contains more than 15.000 objects
AppDbContext.BulkInsert(newTruckCosts); // <-- This takes forever...
MyEntity 有 19 个属性,有 5 个指向其他实体的外键。
我确实尝试了很多,但我真的被困在这里,尤其是对于 15.000 多条记录,它需要很长时间。
会不会因为我的实体有几个外键引用了我数据库中的其他实体,所以花了这么长时间?
此外,不知道这是否重要,我在 Azure(基本层)、.NET Core 和 EntityFramework Core 中使用 SQL 数据库。
因此,通过将 Azure SQL 数据库从基本层升级到标准 S1 层,实现了重大改进。
使用 Basic Tier 只需花费很长时间,现在使用 Standard S1 Tier 大约需要 15 秒,这对我来说完全没问题。