(#4)升级系统支持自动部署数据库
This commit is contained in:
		
							parent
							
								
									81f2c4c6a2
								
							
						
					
					
						commit
						9679df3db5
					
				@ -186,6 +186,7 @@
 | 
			
		||||
    <Compile Include="App_Start\RouteConfig.cs" />
 | 
			
		||||
    <Compile Include="Bll\DesHelper.cs" />
 | 
			
		||||
    <Compile Include="Bll\Cache.cs" />
 | 
			
		||||
    <Compile Include="Dal\Configuration.cs" />
 | 
			
		||||
    <Compile Include="Dal\Queryes\HisDrugQuery.cs" />
 | 
			
		||||
    <Compile Include="Dal\Queryes\HisPrescriptionQuery.cs" />
 | 
			
		||||
    <Compile Include="Dal\Queryes\IDbQuery.cs" />
 | 
			
		||||
@ -255,6 +256,7 @@
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Folder Include="App_Data\" />
 | 
			
		||||
    <Folder Include="Dal\Migrations\" />
 | 
			
		||||
    <Folder Include="Models\" />
 | 
			
		||||
    <Folder Include="Views\Test\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								WebSiteCode/Cmdjy/Cmdjy/Dal/Configuration.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								WebSiteCode/Cmdjy/Cmdjy/Dal/Configuration.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
using System.Data.Entity.Migrations;
 | 
			
		||||
 | 
			
		||||
namespace Cmdjy.Dal
 | 
			
		||||
{
 | 
			
		||||
    internal partial class Configuration:DbMigrationsConfiguration<DjyDbContext>
 | 
			
		||||
    {
 | 
			
		||||
        public Configuration() {
 | 
			
		||||
            AutomaticMigrationsEnabled = WebSettings.AutoMigrations;
 | 
			
		||||
            AutomaticMigrationDataLossAllowed = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void Seed(DjyDbContext context) {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -13,7 +13,6 @@ namespace Cmdjy.Dal
 | 
			
		||||
    public partial class DjyDbContext:DbContext
 | 
			
		||||
    {
 | 
			
		||||
        public DjyDbContext() : base("DjyDbContext") {
 | 
			
		||||
            //Database.SetInitializer<DjyDbContext>(null);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    /// <summary>
 | 
			
		||||
 | 
			
		||||
@ -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<DjyDbContext,Configuration>());
 | 
			
		||||
 | 
			
		||||
            AreaRegistration.RegisterAllAreas();
 | 
			
		||||
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
 | 
			
		||||
            RouteConfig.RegisterRoutes(RouteTable.Routes);
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,8 @@
 | 
			
		||||
    <add key="webpages:Enabled" value="false" />
 | 
			
		||||
    <add key="ClientValidationEnabled" value="true" />
 | 
			
		||||
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
 | 
			
		||||
    <!--自动升级数据库-->
 | 
			
		||||
    <add key="AutoMigrations" value="true"/>
 | 
			
		||||
 | 
			
		||||
    <!--双方协商,需要8位长度,超过8位取8位,小于8位抛出异常-->
 | 
			
		||||
    <add key="DesKey" value="wsddjy19" />
 | 
			
		||||
 | 
			
		||||
@ -39,5 +39,17 @@ namespace Cmdjy
 | 
			
		||||
                return 100;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 自动升级数据库
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static bool AutoMigrations {
 | 
			
		||||
            get {
 | 
			
		||||
                var val = GetValue("AutoMigrations");
 | 
			
		||||
                if(bool.TryParse(val,out bool v)) {
 | 
			
		||||
                    return v;
 | 
			
		||||
                }
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user