title: Getting error during to add some new fields into AspNetUsers
body: <p>I just migrated from ASP.NET MVC to Blazor. I have created a new project that has authorization and authentication. When I want to add a series of new columns to the <code>AspNetUsers</code> table, I frequently encounter various errors.</p>
  <blockquote>
  <p>IdentityUser Issue - Cannot create a DbSet for 'IdentityUser' this type is not included in the model for the context</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>Unable to materialize entity instance of type 'Resource'. No discriminators matched the discriminator value ''.&quot;</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>Cannot create a DbSet for 'IdentityUser' because this type is not included in the model for the context</p>
  </blockquote>
  <p>and</p>
  <blockquote>
  <p>The entity type 'IdentityUserLogin' requires a primary key to be defined</p>
  </blockquote>
  <p>My DbContext looks like this:</p>
  <pre><code>using LoginAndAuthProj.Server.Entities;
  using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal;
  using Microsoft.EntityFrameworkCore.Metadata;
  using Microsoft.EntityFrameworkCore.ValueGeneration.Internal;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  
  namespace LoginAndAuthProj.Server.MainDbContext
  {
      public class ApplicationDbContext : IdentityDbContext
      {
          public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options) { }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;MyEventUserLog&gt;(entity =&gt;
              {
                  var pb = entity.Property(e =&gt; e.UId).ValueGeneratedOnAdd();
  
                  if (Database.IsInMemory())
                  {
                      pb.HasValueGenerator&lt;InMemoryIntegerValueGenerator&lt;decimal&gt;&gt;();
                  }
              });
  
              base.OnModelCreating(modelBuilder);
          }
  
          public DbSet&lt;MyEventUserLog&gt; MyEventUserLogs { get; set; }
      }
  }
  </code></pre>
  <p>And the login controller:</p>
  <pre><code>using LoginAndAuthProj.Shared.DTOs;
  using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.Configuration;
  using Microsoft.IdentityModel.Tokens;
  using System;
  using System.Collections.Generic;
  using System.IdentityModel.Tokens.Jwt;
  using System.Linq;
  using System.Security.Claims;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace LoginAndAuthProj.Server.Controllers
  {
      [ApiController]
      [Route(&quot;api/[controller]&quot;)]
      public class AccountController : ControllerBase
      {
          private readonly UserManager&lt;IdentityUser&gt; _userManager;
          private readonly SignInManager&lt;IdentityUser&gt; _signInManager;
          private readonly IConfiguration _configuration;
  
          public AccountController(UserManager&lt;IdentityUser&gt; userManager, SignInManager&lt;IdentityUser&gt; signInManager,
              IConfiguration configuration)
          {
              _userManager = userManager;
              _signInManager = signInManager;
              _configuration = configuration;
          }
  
          [HttpPost(&quot;Login&quot;)]
          public async Task&lt;ActionResult&lt;UserToken&gt;&gt; Login([FromBody] UserInfo userInfo)
          {
              var result = await _signInManager
                  .PasswordSignInAsync(userInfo.Email, userInfo.StrPassword, false, false);
              UserToken ut = new UserToken();
  
              // if(result.RequiresTwoFactor ==  )
              if (result.Succeeded)
              {
                  ut = BuildToken(userInfo);
                  ut.Responser.ResponsState = Shared.Enumes.ResponserState.Successful;
                  ut.Responser.StrMessage = &quot;Login OK . . .&quot;;
  
                  return ut;
              }
              else
              {
                  if (result.RequiresTwoFactor)
                  {
                      var user = await _userManager.FindByEmailAsync(userInfo.Email);
                      var tokenMain = await _userManager.GenerateTwoFactorTokenAsync(user, &quot;Email&quot;);
                      ut.Responser.StrMessage = tokenMain.ToString();
                      ut.Responser.ResponsState = Shared.Enumes.ResponserState.TwoVerification;
                      Console.WriteLine(ut.Responser.StrMessage);
  
                      return ut;
                  }
                  else
                  {
                      ut.Responser.ResponsState = Shared.Enumes.ResponserState.Fail;
                      ut.Responser.StrMessage = &quot;Login OK . . .&quot;;
                      //return BadRequest(&quot;Login Failed&quot;);
  
                      return ut;
                  }
              }
          }
  
          [HttpPost(&quot;LoginTwoStep&quot;)]
          public async Task&lt;ActionResult&lt;UserToken&gt;&gt; LoginTwoStep([FromBody] UserInfo userInfo)
          {
              try
              {
                  var appUser = await _userManager.FindByEmailAsync(userInfo.Email);
                  var result = await _signInManager.TwoFactorSignInAsync(&quot;Email&quot;, userInfo.StrCode, false, userInfo.CanRememberMe);
  
                  if (result.Succeeded)
                  {
                      return BuildToken(userInfo);
                  }
                  else
                  {
                      UserToken ut = new UserToken();
                      ut.Responser.ResponsState = Shared.Enumes.ResponserState.Fail;
                      ut.Responser.StrMessage = &quot;Code is wrong . . . .&quot;;
                      return ut;
                  }
              }
              catch (Exception ex)
              {
                  String Err = ex.Message;
                  Console.WriteLine(Err);
                  UserToken ut = new UserToken();
                  ut.Responser.ResponsState = Shared.Enumes.ResponserState.Fail;
                  ut.Responser.StrMessage = &quot;Code is wrong . . . .&quot; + Err;
                  return ut;
              }
          }
  
          [HttpPost(&quot;Create&quot;)]
          public async Task&lt;ActionResult&lt;UserToken&gt;&gt; CreateUser([FromBody] UserInfo model)
          {
              var user = new IdentityUser { UserName = model.Email, Email = model.Email, PhoneNumber = &quot;00000011110000&quot;, 
              EmailConfirmed = true, PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEnabled = false, AccessFailedCount = 0};
  
              try
              {
                  var result = await _userManager.CreateAsync(user, model.StrPassword);
  
                  if (result.Succeeded)
                  {
                      return BuildToken(model);
                  }
                  else
                  {
                      return BadRequest(&quot;Username Or Password is invalid&quot;);
                  }
              }
              catch (Exception ex)
              {
                  return BadRequest(ex.Message);
              }
          }
  
          private UserToken BuildToken(UserInfo userInfo)
          {
              var claims = new List&lt;Claim&gt;()
              {
                  new Claim(ClaimTypes.Name, userInfo.Email),
                  new Claim(ClaimTypes.Email, userInfo.Email),
                  new Claim(&quot;MyClaim&quot;, &quot;My Claim Value&quot;)
              };
  
              var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration[&quot;jwt:key&quot;]));
              var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
              var expireDate = DateTime.Now.AddDays(30);
  
              JwtSecurityToken token = new JwtSecurityToken(
                  issuer: null,
                  audience: null,
                  claims: claims,
                  expires: expireDate,
                  signingCredentials: creds
              );
  
              return new UserToken
              {
                  Token = new JwtSecurityTokenHandler().WriteToken(token),
                  ExpireDate = expireDate
              };
          }
      }
  }
  </code></pre>
  <p>Startup file in Server Layer</p>
  <pre><code>using LoginAndAuthProj.Server.MainDbContext;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.HttpsPolicy;
  using Microsoft.AspNetCore.ResponseCompression;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using System.Linq;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Authentication.JwtBearer;
  using System;
  using Microsoft.IdentityModel.Tokens;
  using System.Text;
  using Newtonsoft.Json;
  using LoginAndAuthProj.Shared.DTOs;
  
  namespace LoginAndAuthProj.Server
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(Configuration.GetConnectionString(&quot;DefaultConnection&quot;))
              );
              services.AddControllersWithViews();
              services.AddRazorPages();
              services.AddIdentity&lt;IdentityUser, IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
                  .AddDefaultTokenProviders();
              services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                  .AddJwtBearer(options =&gt;
                  {
                      options.TokenValidationParameters = new TokenValidationParameters
                      {
                          ValidateIssuer = false,
                          ValidateAudience = false,
                          ValidateLifetime = true,
                          ValidateIssuerSigningKey = true,
                          IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration[&quot;jwt:key&quot;])),
                          ClockSkew = TimeSpan.Zero
                      };
                  });
              services.AddMvc().AddNewtonsoftJson(options =&gt; options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
          }
  
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseWebAssemblyDebugging();
              }
              else
              {
                  app.UseExceptionHandler(&quot;/Error&quot;);
                  app.UseHsts();
              }
  
              app.UseHttpsRedirection();
              app.UseBlazorFrameworkFiles();
              app.UseStaticFiles();
              app.UseRouting();
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapRazorPages();
                  endpoints.MapControllers();
                  endpoints.MapFallbackToFile(&quot;index.html&quot;);
              });
          }
      }
  }
  </code></pre>
  <p>I want to add just this three fields to that table</p>
  <pre><code>public String UsersAddress { get; set; }
  public int CityID { get; set; }
  public Byte[] PictureOfUser { get; set; }
  </code></pre>