umair mohsin

umair mohsin

  • 1.4k
  • 387
  • 65.6k

Aspnet identity tables reappear

Jan 29 2024 7:33 PM

i an using aspnet identity in one of my project my project entities are in different project where as identy is a  seperate project(all knows)

i want to link some tables with identity i have linked thm successfully data is also entering appropriately in every table(identity + my project tables)

 

  public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
      Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Migrations.Configuration>());
           // Database.SetInitializer<ApplicationDbContext>(new DropCreateDatabaseIfModelChanges<ApplicationDbContext>());
            //Database.SetInitializer<ApplicationDbContext>(new DropCreateDatabaseAlways<ApplicationDbContext>());
            //Database.SetInitializer<SchoolDBContext>(new SchoolDBInitializer());

        }

automaticmigrations are set to true in configuration.cs of migartion folder of this project

i have changed my identity db table names using this
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);


            modelBuilder.Entity<ApplicationUser>().ToTable("Users");
            modelBuilder.Entity<IdentityRole>().ToTable("Role");
            modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole");
            modelBuilder.Entity<IdentityUserClaim>().ToTable("Claim");
            modelBuilder.Entity<IdentityUserLogin>().ToTable("Login");

        }


        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

       

    }

        public virtual Employer Employer { get; set; }
        public virtual Candidate Candidate { get; set; }

 

above lines link my tables to aspnet identity

on registration i entered data in one of my tables data entered successfully in identity and my tables but all identity tables regenerate with their original names with no data and other tables have data what i inserted.this problem is little annoying.if i manually delete these tables and next time register any employer these tables will regenerate again.

how to handle this. 

 

 


Answers (1)