Entity Framework数据库初始化
时间:2021-07-01 10:21:17
帮助过:8人阅读
class ApplicationContext : DbContext
{
public DbSet<User> Users {
get;
set; }
public ApplicationContext()
: base(
"ApplicationConnection")
{
//Database.Create();
Database.SetInitializer(
new SystemInitializer());
}
}
public class SystemInitializer : DropCreateDatabaseIfModelChanges<ApplicationContext>
{
protected override void Seed(ApplicationContext context)
{
var user =
new User()
{
UserName=
"admin",
DisplayName=
"系统管理员",
Password =
"admin",
Email=
"admintest@126.com"
};
context.Users.Add(user);
}
}
Entity Framework数据库初始化
标签: