I am working on a Web Application NET6.0 with Individual Account. After creating the application, I scaffolded the Identity items and selected to override all files. I also decided to use my existing ApplicationDbContext. Then, in my ApplicationDbContext.cs, I Created a unique Identity Schema for the default User tables. Firthermore, I added two additional tables, Contact & InvestorRelations), with their respective ContactViewModel and InvestorRelationsModel to the list and created a View Model for each. My Override looks like this:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.HasDefaultSchema("Identity");
builder.Entity<InvestorRelationsModel>(entity =>
{
entity.ToTable(name: "InvestorRelations");
});
builder.Entity<ContactViewModel>(entity=>
{
entity.ToTable(name: "Contact");
});
builder.Entity<IdentityUser>(entity =>
{
entity.ToTable(name: "User");
entity.Property<string>("FullName").HasMaxLength(200);
});
builder.Entity<IdentityRole>(entity =>
{
entity.ToTable(name: "Role");
});
builder.Entity<IdentityUserRole<string>>(entity =>
{
entity.ToTable("UserRoles");
});
builder.Entity<IdentityUserClaim<string>>(entity =>
{
entity.ToTable("UserClaims");
});
builder.Entity<IdentityUserLogin<string>>(entity =>
{
entity.ToTable("UserLogins");
});
builder.Entity<IdentityRoleClaim<string>>(entity =>
{
entity.ToTable("RoleClaims");
});
builder.Entity<IdentityUserToken<string>>(entity =>
{
entity.ToTable("UserTokens");
});
}
I created a new migration and updated the database without errors. However, when I ran the pplication, and navigated to the Register page, The following error message appeared:
An unhandled exception occurred while processing the request.
InvalidOperationException: The model item passed into the ViewDataDictionary is of type '_200Blue.Areas.Identity.Pages.Account.RegisterModel', but this ViewDataDictionary instance requires a model item of type '_200Blue.Models.ContactViewModel'.
I am not sure how to fix this error. I did not modify the Register.cshtml.cs file and only have the one Models/ContactViewModel.cs that I created to save my Web Emails into the Database.
Any assistance or recommendations would be appreciated.