public 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); } }