I\'m trying (but failing) to implement the MVC UserManager
to my website. I thought my case is fairly trivial. I have a User
class (Entity Framewor
The problem is that you're trying to add a User you added to one DbContext to a ApplicationUser you add to a different DbContext (created by the UserManager).
Instead, you should do this as a single operation. Just do this:
var dbUser = new User
{
Firstname = model.FirstName,
Lastname = model.LastName,
Email = model.UserName
};
var appUser = new ApplicationUser(model.UserName);
appUser.UserInfo = dbUser;
try
{
var result = await UserManager.CreateAsync(appUser, model.Password);
}
catch (Exception e)
{
// show error or whatever
}