相关疑难解决方法(0)

实体框架种子与身份(Microsoft.Owin.Security)用户

我有一个为数据库设置种子的类,它为2个用户添加了角色和自定义字段.我遇到的问题是它将数据保存在[dbo].[AspNetUsers]而不是[dbo].[IdentityUsers].两个表都已创建.播种时,数据进入AspNetUser.当我启动网站并注册新用户时,数据将进入IdentityUser.

这是Migration类:

internal sealed class Configuration : DbMigrationsConfiguration<DatabaseContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(DatabaseContext context)
    {
        base.Seed(context);

        var userStore = new UserStore<ApplicationUser>();
        var manager = new UserManager<ApplicationUser>(userStore);

        var role = new IdentityUserRole { Role = new IdentityRole(Model.Roles.ADMINISTRATOR) };
        var user = new ApplicationUser() { UserName = "123123", Email = "123123@123.com", Language = "en-US"};
        user.Roles.Add(role);
        IdentityResult result = manager.Create(user, "123123");

        var role2 = new IdentityUserRole { Role = new IdentityRole(Model.Roles.NORMAL) };
        var user2 = new …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc entity-framework entity-framework-6 asp.net-identity

5
推荐指数
1
解决办法
6399
查看次数