初始化项目
This commit is contained in:
52
Models/DBInit.cs
Normal file
52
Models/DBInit.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
|
||||
using Models.ModelItems;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web.Security;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
//数据库模型不一致时创建
|
||||
//DropCreateDatabaseIfModelChanges
|
||||
//默认 不存在时创建
|
||||
// CreateDatabaseIfNotExists
|
||||
// DropCreateDatabaseAlways:每次运行时都重新生成数据
|
||||
public class DBInit : CreateDatabaseIfNotExists<AuthorityDB>
|
||||
{
|
||||
|
||||
//继承三种内置的初始化器中的DropCreateDatabaseAlways
|
||||
protected override void Seed(AuthorityDB context)
|
||||
{
|
||||
try
|
||||
{
|
||||
//添加约束 适当修改
|
||||
string sql = File.ReadAllText(AppContext.BaseDirectory + "App_Data\\configs\\Constraint.sql").Replace("go", "").Replace("GO", "");
|
||||
context.Database.ExecuteSqlCommand(sql);
|
||||
//添加触发器 不用
|
||||
sql = File.ReadAllText(AppContext.BaseDirectory + "App_Data\\configs\\trigger.sql").Replace("go", "").Replace("GO", "");
|
||||
context.Database.ExecuteSqlCommand(sql);
|
||||
//创建视图
|
||||
sql = File.ReadAllText(AppContext.BaseDirectory + "App_Data\\configs\\ViewInit.sql").Replace("go", "").Replace("GO", "");
|
||||
context.Database.ExecuteSqlCommand(sql);
|
||||
//初始化数据 这块暂不处理
|
||||
sql = File.ReadAllText(AppContext.BaseDirectory + "App_Data\\configs\\InitData.sql").Replace("go", "").Replace("GO", "");
|
||||
context.Database.ExecuteSqlCommand(sql);
|
||||
//同步酒店人员信息 这块暂时无效
|
||||
sql = File.ReadAllText(AppContext.BaseDirectory + "App_Data\\configs\\datasql.sql").Replace("go", "").Replace("GO", "");
|
||||
context.Database.ExecuteSqlCommand(sql);
|
||||
base.Seed(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
File.WriteAllLines(AppContext.BaseDirectory + "App_Data\\DBINITerr.txt", new string[] { ex.ToString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user