将链接表的主键添加到ASPNETUsers表Id字段

时间:2017-03-08 05:13:09

标签: asp.net-mvc entity-framework-6 asp.net-identity claims-based-identity

我已成功将aspnetusers表链接到我的自定义用户表作为一对一关系。现在,当我去注册时,所有信息都成功添加到两个表中,除了一件事 - Id。

我的用户表中的pk userId是一个AutoIncrement键,我希望在aspnetUsers表的id字段中添加相同的值。我想我将不得不覆盖createAsync或从SignInAsync中删除

await user.GenerateUserIdentityAsync(UserManager)

AccountController 注册方法中,我有

    public async Task<ActionResult> Register(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var geUser  = new User { Password = model.Password, Username = model.Email, AccessLevel = "0003", LoggedIn = false, Active = true, AllowOffline = false, LastSettingsRefreshed = DateTime.Now };

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email,  user = geUser};
            IdentityResult result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                await SignInAsync(user, isPersistent: false);

                return RedirectToAction("Index", "Home");
            }
            else
            {
                AddErrors(result);
            }
        }

        return View(model);
    }

我的数据表: ASPNetUSers和用户分别:

enter image description here

我想在aspnetusers表中输入43而不是0

更新

在研究中,我发现它与 DatabaseGeneratedOption 有关,但确切地说我应该做什么以及在哪个表上做什么&#34; DatabaseGeneratedOption.None&#34;?

0 个答案:

没有答案