c# - Automatic Migration and manual invocation of Update-Database -
do have manually issue update-database
command in package manager console though have automatic migrations turned on?
i'm running mvc4 , ef6. solution targeted .net 4 (i can't change unfortunately).
edit: i'm aware of difference between code migrations require me seed existing tables. question more based towards scenario add table has no relations, think run?
edit 2: table should added automatically
============
new table definition
public class inboundfile : entity { [required] public string filepath { get; set; } }
ef config file
public configuration() { automaticmigrationsenabled = true; automaticmigrationdatalossallowed = true; migrationsdirectory = @"migrations"; } protected override void seed(unifi.context.dbcontext context) { context.inboundfiles.addorupdate( x => x.filepath, new inboundfile { createdate = datetime.now, modifieddate = datetime.now, filepath = "c:/test", isdeleted = false } ); }
db context
public class dbcontext : dbcontext {
public dbcontext() : base("myconn") { } public dbset<user> users { get; set; } public dbset<userrole> userroles { get; set; } public dbset<region> regions { get; set; } public dbset<inboundfile> inboundfiles { get; set; } }
try placing in application_start
database.setinitializer(new migratedatabasetolatestversion<dbcontext, configuration>); using (var temp = new dbcontext()) { temp.database.initialize(true); }
this force run update-database
, , in doing seed
, every time application starts.
Comments
Post a Comment