dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.41k stars 3.11k forks source link

Sql Bulk Operation as Part of a Migration #33724

Closed christophwille closed 2 weeks ago

christophwille commented 2 weeks ago

We have the issue of having to seed a rather big reference table (ok, tables) as part of an EF migration. The normal EF approach broke down (basically the build OOMed), so we switched to executing a .sql script as part of the migration (which is nicely supported, thank you). However, if we compare those INSERTs to a bulk copy approach like eg https://www.krisvandermast.com/post/2022/03/23/using-sqlbulkcopy-with-dotnet-lists.html, the performance is still abysmal.

Is there any way to hook into a specific migration and execute the seeding using bulk copy? I have seen issues that looked similar but weren't, but maybe I was looking with the wrong search terms. (and yes, I really want to lock a specific bulk copy operation to a specific migration, really replacing standard seeding with it).

Is that possible at all?

AndriySvyryd commented 2 weeks ago

Currently this is not possible. https://github.com/dotnet/efcore/issues/24710 would enable this as it tracks adding generic lifecycle hooks that run before and after every migration.