我想将数据添加到用户定义的表中,即性别表。我从代码中添加角色,但角色表是在项目中内置的。下面是我的代码,我在startup.cs中通过代码在内置表中创建角色,但是如何在用户定义的表中添加数据。
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
CreateRolesandUsers();
}
private void CreateRolesandUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
// In Startup I am creating first Admin Role and creating a default Admin User
if (!roleManager.RoleExists("Admin"))
{
// first we create Admin role
var role = new IdentityRole();
role.Name = "Admin";
roleManager.Create(role);
}
//creating Creating Manager role
if (!roleManager.RoleExists("Manager"))
{
var role = new IdentityRole();
role.Name = "Manager";
roleManager.Create(role);
}
//creating Creating Judge role
if (!roleManager.RoleExists("Judge"))
{
var role = new IdentityRole();
role.Name = "Judge";
roleManager.Create(role);
}
//creating Creating Police role
if (!roleManager.RoleExists("Police"))
{
var role = new IdentityRole();
role.Name = "Police";
roleManager.Create(role);
}
//creating Creating Jailer role
if (!roleManager.RoleExists("Jailer"))
{
var role = new IdentityRole();
role.Name = "Jailer";
roleManager.Create(role);
}
}