InvalidOperationException when registering a new user with ASP .NET Core Identity and EntityFrameworkCore

后端 未结 2 1763
耶瑟儿~
耶瑟儿~ 2021-01-18 21:09

I\'m following the documentation for using Identity and am trying register a new user (executing the register action), but it fails with the following error:

2条回答
  •  耶瑟儿~
    2021-01-18 22:10

    Create new context class which inherit IdentityDbContext.

    public class ApplicationDbContext : IdentityDbContext
    {
        public ApplicationDbContext(DbContextOptions options)
            : base(options)
        {
        }
    
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }
    }
    

    and in startup.cs file add below code

    services.AddDbContext(options =>
                options.UseSqlServer(connection));
    

    This will help you for database first approach.

提交回复
热议问题