0

Users table

 [Table("Users")]
   public  class User : IdentityUser
    {
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        [Required]
        [Display(Name = "Name")]
        public string Name { get; set; }
        [Required]
        [Display(Name = "Gender")]
        public string Gender { get; set; }

        [Required]
        [Display(Name = "Date of birth")]
        public string DateOfBirth { get; set; }
    }

MyContext Class

 public class myContext : IdentityDbContext<User>
    {
        public myContext() : base("DefaultConnection")
        {
        }
        public static myContext Create()
        {
            return new myContext();
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo");
            modelBuilder.Entity<IdentityRole>().ToTable("Roles", "dbo");
            modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles", "dbo");
            modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims", "dbo");
            modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins", "dbo");
        }

    }

This is creating two tables

  1. AspNetUsers - with additiona fields
  2. Users - with default fields

Note sure what am I missing here. How can I have the additional fields also in Users table

0

1 Answer 1

1

You need to change the line in OnModelCreating in myContext:

 modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo");

to:

 modelBuilder.Entity<User>().ToTable("Users", "dbo");

Right now, it is creating two tables because you have defined IdentityUser type to be used to create table named Users and one default table is getting created against IdentityUser type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.