Create data during EF6 migrations
Hey guys, in our project we use some kind of "changelog implementation" to track all changes in our data. For some reason we also need to create changelongs with default values in case we add let says new columns to DB tables and I dont know what's the best way to do it. Currently I'm playing with some kind of DbCommandInterceptor that detects DB update process (applying migrations), parse them and create records accordingly but I'm not sure if that's correct approach. One of the reason I dont like it it's because it has to parse every command to DB and calculate if it is or if it's not the migration but maybe there is smarter way to do that. Any experience with it ? Thanks
7 Replies
if it's exclusively part of the migration then why not put it in the migration itself?
You mean put some "seed" kode to migration file itself ? But I dont want to write these updates manually
I'd agree that you might want to put this into a migration
If you're looking for automation, you might be able to do something with https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/operations#using-a-migrationoperation
Custom Migrations Operations - EF Core
Managing custom and raw SQL migrations for database schema management with Entity Framework Core
You could intercept the sql generation, still delegate the sql generation to the base class, but create your custom logic accordingly
By EF6 do you mean old EF, or Core?
old EF