When using GeneratePasswordResetTokenAsync I get three invalid column warnings, two for UserId and one for RoleId. I believe this has something to do with AspNetUsers relationships, which I have not edited in my database. I am running the code below. I've edited the code below to show where dbUser is derived from, which gets its context from the web.config's DefaultConnection.
using (var appContext = ApplicationDbContext.Create())
{
var dbUser = appContext.Users.FirstOrDefault(x => x.UserName == Username);
if (dbUser.EmailConfirmed)
{
var provider = Startup.DataProtectionProvider;
var userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(appContext));
userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("PasswordReset"));
token = await userManager.GeneratePasswordResetTokenAsync(dbUser.Id);
...
}
}
I tried adding an extended context with this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<AspNetUser>()
.HasMany(n => n.AspNetUserClaims)
.WithRequired()
.Map(a => a.MapKey("UserId"));
modelBuilder.Entity<AspNetUser>()
.HasMany(n => n.AspNetUserLogins)
.WithRequired()
.Map(a => a.MapKey("UserId"));
modelBuilder.Entity<AspNetUser>()
.HasMany(n => n.AspNetRoles)
.WithRequired()
.Map(a => a.MapKey("RoleId"));
}
But this had no effect. What I don't understand is why the call to GeneratePasswordResetTokenAsync would not understand the relationship to it's connected tables, they are all AspNet_X tables. In other words they are AspNetRoles (through AspNetUserRoles), AspNetUserClaims, and AspNetUserLogins.
Am I just looking at this issue wrong?