本文介绍了我的应用程序我使用的是ASP身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i

 create asp.net identity application in this application i used custom class Name Called ApplicationRole and That class is inherited with IdentityRole 

public class ApplicationRole:IdentityRole
{
       public ApplicationRole():base()  { }
       public bool IsSuperAdmin { get; set; }
}
 and then i used this class on the <pre lang="C#">OnModelCreating Method</pre>

protected override void OnModelCreating(DbModelBuilder modelBuilder)
       {
           base.OnModelCreating(modelBuilder);
           modelBuilder.Entity&lt;ApplicationUser&gt;().ToTable(&quot;tblUser&quot;).Property(x =&gt; x.Id).HasColumnName(&quot;UserID&quot;);
           modelBuilder.Entity&lt;ApplicationRole&gt;().ToTable(&quot;tblRoles&quot;).Property(x =&gt; x.Id).HasColumnName(&quot;RoleID&quot;);
           modelBuilder.Entity&lt;IdentityUserRole&gt;().ToTable(&quot;tblUserRole&quot;).Property(x =&gt; x.RoleId).HasColumnName(&quot;RoleID&quot;);
           modelBuilder.Entity&lt;IdentityUserRole&gt;().ToTable(&quot;tblUserRole&quot;).Property(x =&gt; x.UserId).HasColumnName(&quot;UserID&quot;);
           modelBuilder.Entity&lt;IdentityUserClaim&gt;().ToTable(&quot;tblUserClaim&quot;).Property(x =&gt; x.Id).HasColumnName(&quot;ClaimID&quot;);
           modelBuilder.Entity&lt;IdentityUserLogin&gt;().ToTable(&quot;tblUserLogin&quot;);


       }
after this i used Add-migrations and then update-DataBase
now i opened sql Server it will create aspnetRole table extra





我尝试过:



公共类ApplicationRole:IdentityRole

{

public ApplicationRole():base(){}

public虚拟Office OfficeID {get;组; }

public bool IsSuperAdmin {get;组; }

}



公共类办公室

{

[Key]

public long OfficeID {get;组; }

公共字符串OfficeName {get;组; }

公共虚拟ICollection< applicationuser>用户{get;组; }

public virtual ICollection< applicationrole>角色{get;组; }

}







protected override void OnModelCreating(DbModelBuilder modelBuilder)

{



base.OnModelCreating(modelBuilder);

modelBuilder.Entity< ApplicationUser>()。ToTable (用户)。属性(x => x.Id).HasColumnName(UserID);

modelBuilder.Entity< IdentityUserRole>()。ToTable(UserRole);

modelBuilder.Entity< IdentityUserClaim>()。ToTable(UserClaims)。Property(x => x.Id).HasColumnName(ClaimID);

modelBuilder。实体< IdentityUserLogin>()。ToTable(UserLogin);

modelBuilder.Entity< ApplicationRole>()。ToTable(Roles)。Property(x => x.Id).HasColumnName (RoleID);



}



What I have tried:

public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public virtual Office OfficeID { get; set; }
public bool IsSuperAdmin { get; set; }
}

public class Office
{
[Key]
public long OfficeID { get; set; }
public string OfficeName { get; set; }
public virtual ICollection<applicationuser> User { get; set; }
public virtual ICollection<applicationrole> Role { get; set; }
}



protected override void OnModelCreating(DbModelBuilder modelBuilder)
{

base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().ToTable("User").Property(x => x.Id).HasColumnName("UserID");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims").Property(x => x.Id).HasColumnName("ClaimID");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogin");
modelBuilder.Entity<ApplicationRole>().ToTable("Roles").Property(x => x.Id).HasColumnName("RoleID");

}

推荐答案


这篇关于我的应用程序我使用的是ASP身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 03:04