diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index 7694660..859184e 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -186,6 +186,7 @@ + @@ -255,6 +256,7 @@ + diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Configuration.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Configuration.cs new file mode 100644 index 0000000..59dd461 --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Configuration.cs @@ -0,0 +1,17 @@ +using System.Data.Entity.Migrations; + +namespace Cmdjy.Dal +{ + internal partial class Configuration:DbMigrationsConfiguration + { + public Configuration() { + AutomaticMigrationsEnabled = WebSettings.AutoMigrations; + AutomaticMigrationDataLossAllowed = true; + } + + protected override void Seed(DjyDbContext context) { + + } + + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs index 4f01cbb..2907aa6 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs @@ -13,7 +13,6 @@ namespace Cmdjy.Dal public partial class DjyDbContext:DbContext { public DjyDbContext() : base("DjyDbContext") { - //Database.SetInitializer(null); } } /// diff --git a/WebSiteCode/Cmdjy/Cmdjy/Global.asax.cs b/WebSiteCode/Cmdjy/Cmdjy/Global.asax.cs index 54b057d..7476c9a 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Global.asax.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Global.asax.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; +using System.Data.Entity; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; +using Cmdjy.Dal; namespace Cmdjy { public class MvcApplication:System.Web.HttpApplication { protected void Application_Start() { + Database.SetInitializer(new MigrateDatabaseToLatestVersion()); + AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); diff --git a/WebSiteCode/Cmdjy/Cmdjy/Web.config b/WebSiteCode/Cmdjy/Cmdjy/Web.config index ed1eddc..474f0ca 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Web.config +++ b/WebSiteCode/Cmdjy/Cmdjy/Web.config @@ -13,6 +13,8 @@ + + diff --git a/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs b/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs index e23cc23..3c5295c 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/WebSettings.cs @@ -39,5 +39,17 @@ namespace Cmdjy return 100; } } + /// + /// 自动升级数据库 + /// + public static bool AutoMigrations { + get { + var val = GetValue("AutoMigrations"); + if(bool.TryParse(val,out bool v)) { + return v; + } + return true; + } + } } } \ No newline at end of file