简体   繁体   中英

How to Inherit from IdentityUserLogin And IdentityUserRole asp.net mvc

I have a two classes they are names tblUserProfile and tblUserRole I want to add multiple property to my own class that i mentioned.in fact , tblUserProfile use tblUserProfile:IdentityUserLogin and tblUserRole use tblAccessRole : IdentityUserRole but when I did add-migration it did give me this error EntityType has no key defined. Define the key for this EntityType EntityType has no key defined. Define the key for this EntityType after that I add key attribute then EF did show me Column names in each table must be unique. Column name 'RoleId' in table 'tblAccessRoles' is specified more than once. Column names in each table must be unique. Column name 'RoleId' in table 'tblAccessRoles' is specified more than once. please tell me how can i solve it.

   public class tblUserProfile : IdentityUserLogin
    {
        public int UserID { get; set; }
        public string NameFamily { get; set; }

    }

  public class tblAccessRole : IdentityUserRole
    {

        public int RoleID { get; set; }
        public string  Section { get; set; }
        public bool IsSave { get; set; }
    }

remove UserID from tblUserProfile and RoleID from tblAccessRole and

In Your DbContext add :

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

      modelBuilder.Entity<tblUserProfile>()//IdentityUserLogin
            .HasKey(l => new { l.LoginProvider, l.ProviderKey, l.UserId })
            .ToTable("tblUserProfile");// Database Table Nam    

            modelBuilder.Entity<tblAccessRole>()//IdentityUserRole
            .HasKey(r => new { r.UserId, r.RoleId })
                .ToTable("tblAccessRole");// Database Table Name
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM