错误提示
<title>Schema specified is not valid. Errors: The relationship 'Service.Sys_Role_Permissions' was not loaded because the type 'Service.Sys_Permission' is not available.</title>
public class Sys_Role : BaseEntity
{
/// <summary>
/// 角色名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
//既可以一张表对应一个Entity,关系表也建立实体,也可以像这样直接让对象带属性,隐式的关系表
public virtual ICollection<Sys_Permission> Permissions { get; set; } = new List<Sys_Permission>();
public virtual ICollection<Sys_Permission> Menus { get; set; } = new List<Sys_Permission>();
public virtual ICollection<Sys_User> SysUsers { get; set; } = new List<Sys_User>();
}
public class Sys_Permission
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime CreateDateTime
{
get { return _CreateDateTime; }
set { _CreateDateTime = value; }
}
public bool IsDeleted
{
get { return _IsDeleted; }
set { _IsDeleted = value; }
}
private DateTime _CreateDateTime = DateTime.Now;
private bool _IsDeleted = false;
public virtual ICollection<Sys_Role> Roles { get; set; } = new List<Sys_Role>();
}
class Sys_Permission_Config : EntityTypeConfiguration<Sys_Permission>
{
public Sys_Permission_Config()
{
ToTable("Sys_Permission");
//HasMany(r => r.Roles).WithMany(p => p.Permissions).Map(m => m.ToTable("Sys_RolePermission")
// .MapLeftKey("PermissionId").MapRightKey("RoleId"));
}
}
class Sys_Role_Config :EntityTypeConfiguration<Sys_Role>
{
public Sys_Role_Config()
{
ToTable("Sys_Role");
HasMany(r => r.Permissions).WithMany(p => p.Roles).Map(m => m.ToTable("Sys_RolePermission")
.MapLeftKey("RoleId").MapRightKey("PermissionId"));
HasMany(r => r.Menus).WithMany(p => p.Roles).Map(m => m.ToTable("Sys_RoleMenu")
.MapLeftKey("RoleId").MapRightKey("MenuId"));
HasMany(r => r.SysUsers).WithMany(p => p.Roles).Map(m => m.ToTable("Sys_UserRole")
.MapLeftKey("RoleId").MapRightKey("UserId"));
}
}
Sys_Role
的主键定义的了吗?