c# - MigrateDatabaseToLatestVersion initializer failing to create database -
I'm trying to create a database to use the first migration of EF code if it does not exist yet , I've successfully done This is the main part of my main method. All I have read says that I want it all in what I think from Instanting a DbContext does not execute it from the initiator, instead, you need to update the database Or need to call the initiator directly on the underlying database. enabled-migration I have also used
add-migration to create the initial migration of the database. The script is in the migration direction and looks correct.
Database .Set Inchylizer (New MigrateDataLoautWarson & lt; MyDbContext, Configuration & gt; ()); Var directConfigContext = new MyDbContext ();
MyDbContext in
app.config and looks like this:
& lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; Configuration & gt; & Lt; ConnectionStrings & gt; & Lt; Add name = "MyDbContext" connectionString = "data source = (localdb) \ v11.0; initial catalog = dbcfif; integrated security = true; multipleactive serialset = true" provider name = "system.data .sql client" /> & Lt; / ConnectionStrings & gt; & Lt; Startup & gt; & Lt; Supported serial version = "v4.0" sku = ".NETFramework, version = v4.5" /> & Lt; / Startup & gt; & Lt; / Configuration & gt; Additionally, if I use the DBMiater class provided by EF, then the database is created correctly (presumably using the initial database migration script).
// How does this actually work with creating databases if it does not exist var dbmigrator = new DbMigrator (new configuration ()); DbMigrator.Update (); I am setting the initializer to
MyDbContext and later indicates that
DbContext is the latest migration to the database Should make in .. What am I missing?
MyDbContext.MyEntity.Add (New MyEntity {Name = "Nelson"}); // or MyDb.Context.Database.Initialize (true); // Force initialization
Comments
Post a Comment