SQLEXPRESS dependency in Code First Migrations Alpha 3


  • We are using Code First Migrations Alpha 3 with Entity Framework & MVC3. We are running into a problem after we are able to successfully add migrations and update our database:

    Our model validation is failing for certain entities when seeding, which is very strange because the exact same validation was working when we were seeding via DbContextInitialization (before we started down the path of using EntityFramework.Migrations). 

    We've used Debugger.Launch() to attach to the Validation method in our model kicked off from Package Manager when we use the 'update-database' command. What we saw was that when we initialize a new DbContext object within that validation, it is using a SQLEXPRESS database instead of the one which we specify in our web.config. This only seems to be happening during seeding - it uses the correct database connection when it applies migrations.

    I know that in prior builds of SQL Migrations, there were some SQLEXPRESS dependencies which they had planned on removing - I think this may be related? I guess we could work around this by forcibly setting the connection when instantiating the DbContext in our model, but that seems very clunky since we don't have to do that anywhere else.

    Thursday, September 29, 2011 2:35 PM

All replies