53 lines
2.1 KiB
C#
53 lines
2.1 KiB
C#
|
||
|
||
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() });
|
||
}
|
||
}
|
||
}
|
||
}
|