首页新闻找找看学习计划

EF错误.看了好久不知道如何下手

0
悬赏园豆:50 [待解决问题]

错误提示
<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"));
    }
}
王银龙的主页 王银龙 | 初学一级 | 园豆:160
提问于:2018-11-22 17:13
< >
分享
所有回答(1)
0

Sys_Role 的主键定义的了吗?

dudu | 园豆:40882 (高人七级) | 2018-11-22 17:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册