[Table("UserMaster")]
public class UserMaster
{
public UserMaster()
{
this.Roles = new List<Role>();
}
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
public ICollection<Role> Roles { get; set; }
}
[Table("Role")]
public class Role
{
public Role()
{
this.Users = new List<UserMaster>();
}
public int RoleId{ get; set; }
public string Name{ get; set; }
public ICollection<UserMaster> Users { get; set; }
}
我使用 EntityTypeConfiguration 映射这些表并触发 OnModelCreate
this.HasMany(a => a.Roles).WithMany(b => b.Users).Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
m.ToTable("UsersInRoles");
});
我想知道是否有办法将它们映射到 Role 或 UserMaster 类中。我们可以用
[ForeignKey()]
[Key]
[Table()]
我们也可以做映射吗?