I use the following code in my Global.asax:
DbDatabase.SetInitializer<MyDBContext>
(new DropCreateDatabaseIfModelChanges<MyDBContext>());
but it doesn't seem to work.
Although my Model has changed and I'm trying to use one of the newly added table's it just says the table could not be found.
Invalid object name 'dbo.TableName'.
If I run this however, it seems to work, and the table is being created:
DbDatabase.SetInitializer<MyDBContext>(new DropCreateDatabaseAlways<MyDBContext>());
It does update my database.
What is it I do wrong?
For what it's worth, I ran into a lot of trouble with both of the DropCreate strategies because Cassini was still running after I closed the browser. (I had the same problem with IIS Express.) Because the local web server was still running, Application_Start
didn't fire again, so the initialization I put there never got executed.
I resolved it by enabling Edit and Continue:
Project properties > Web > Debuggers > Enable Edit and Continue
This forces the local web server to close when the browser closes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With