指定的包含路径在预先加载时无效

时间:2018-04-16 05:53:22

标签: asp.net-mvc entity-framework eager-loading

我在实体框架中使用急切加载。我的Model类就像

public class EmployeeMaster : AbsCommonParameters
{
    [Key]
    public int Id { get; set; }
    public string EmpId { get; set; }

    [Required(ErrorMessage = "Employee name is required")]
    public string Name { get; set; }

    [Required(ErrorMessage = "Employee geography is required")]
    public string Geography { get; set; }

    public string EmailId { get; set; }

    [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [Column(TypeName = "Date")]
    [Display(Name = "Date Of Joining")]
    public Nullable<DateTime> DOJ { get; set; }

    [Required(ErrorMessage = "Employee designation is required")]
    public string Designation { get; set; }

    [NotMapped]
    public List<CenterMaster> lstCenters { get; set; }

    [NotMapped]
    public List<CostCodeMaster> lstCostCode { get; set; }

}

在Controller Index Action中,我的代码就像这样

public ActionResult Index()
{
   var lstUser = db.ObjEmployeeMaster.Include(p => p.lstCenters).
   Include(p => p.lstCostCode).Where(x => x.DeletedStatus == false).ToList();
   return View(lstUser);
}

同样在DBContext构造函数中我使用了

this.Configuration.LazyLoadingEnabled = false;

在此之后我收到了错误

  

指定的包含路径无效

请在我错的地方帮忙。 提前谢谢。

0 个答案:

没有答案