Add Primary Key of Linked Table to ASPNETUsers table Id field

我的梦境 提交于 2019-12-25 05:37:30

问题


I have successfully linked aspnetusers table to my custom users table as one-to-one relationship. Now when i go to register all information is successfully added to both tables except one thing - Id.

My pk userId in users table is an AutoIncrement key and i wish to add the same value in the id field of aspnetUsers table. I think i will have to override createAsync or do i remove from SignInAsync

await user.GenerateUserIdentityAsync(UserManager)

Inside AccountController Register method, I have

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

My Data Tables: ASPNetUSers and Users respectively:

I want to enter 43 instead of 0 in aspnetusers table

UPDATE

On research i see that it has something to do with DatabaseGeneratedOption but exactly what and on which table should i do "DatabaseGeneratedOption.None"?

来源:https://stackoverflow.com/questions/42663471/add-primary-key-of-linked-table-to-aspnetusers-table-id-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!