加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – MVC包含路径无效错误

发布时间:2020-12-16 09:19:58 所属栏目:asp.Net 来源:网络整理
导读:调节器 public ActionResult Index(int? id){ var userEmail = User.Identity.Name; var model = db.Staffs.Where(i = i.Email == userEmail).Include("Histories").Include("CurrentApplications").FirstOrDefault(); return View(model);} 行var var model
调节器

public ActionResult Index(int? id)
{
    var userEmail = User.Identity.Name;
    var model = db.Staffs.Where(i => i.Email == userEmail).Include("Histories").Include("CurrentApplications").FirstOrDefault();


    return View(model);
}

行var var model = db.Staffs.Where(i => i.Email == userEmail).Include(“Histories”).包含(“CurrentApplications”).FirstOrDefault();但我不知道为什么我得到它.

错误

A specified Include path is not valid. The EntityType
‘StaffPortalDBModel.Staff’ does not declare a navigation property with
the name ‘Histories’.

员工班

public partial class Staff
{
    public int StaffID { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public Nullable<decimal> AllocatedLeave { get; set; }
    public Nullable<int> BalanceLeave { get; set; }

    public virtual IEnumerable<History> Histories { get; set; }
    public virtual IEnumerable<CurrentApplication> CurrentApplications { get; set; }
}

解决方法

我相信在定义Navigation属性时可能需要使用ICollection而不是IEnumerable.这可能是个问题.

我还建议(假设您的Entity Framework版本足够高,以支持它)使用强类型包含,这样如果您在Staff.cs中更改属性,您将收到编译时错误.

即:.Include(s => s.Histories)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读