I am creating a code first MVC app with a separate class libraries for my Service layer, POCOs and Repository layer. In the Repository layer I have EF implementaions of my IRepository classes, a DbContext and the required references to Entity Framework. My MVC project does not reference EF.
Is there a way to setup my solution so that the database is recreated and seeded after a model change? All of the examples I have seen so far initialise this in the Global.asax file of an MVC project but my MVC project is independant of EF and has no access to the DbContext.
You could register the initializer in a static constructor of your context:
Using a derived initializer which is in your Repository implementation library as well:
The static constructor would be executed when you create the first context instance and
Seedwill be called when you run a query, add or attach an entity to the context for the first time, etc.