I am using Entity Framework (4.3) migrations. I have a config class as normal that defines a Seed method, which is supposed to called after the migrations to add the data:
internal sealed class SettingsConfig : DbMigrationsConfiguration<My.Assembly>
{
public SettingsConfig()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(ScannerAreaManager.DataAccess.CableSenseLocal context)
{
// This method will be called after migrating to the latest version.
}
}
I’m running SQL Server profiler to see what’s happening to the database.
Now, if I delete the database, and run this application from Visual studio with F5 (attached to debugger), it runs, and I can see the database gets created, migrations run, and the seed method being called and adding data to the database
If I then delete my database, and run the application again with Ctrl-F5 (NOT attached to the debugger), then I see my database gets created, the migrations run, but the seed method never gets called.
Surely this isn’t by design? Any ideas?
My bad, this was caused by our code attempting to read from the context before it had been initialised – but only when not run in debug mode.
EF does indeed behave as expected – the seed method gets called after the migrations have executed.