我有以下代码以惰性模式加载实体,我试图通过添加这行代码将延迟加载设置为false
context.Configuration.LazyLoadingEnabled = false;
到函数的顶部,看看会发生什么,我期望抛出一个异常,但没有发生任何事情并且代码正常执行,所以任何人都可以解释当我关闭延迟加载时会发生什么。
public List<Report> GetReportsByRole(int numberOfRecords, int pageNumber)
{
if (CurrentUser.Role == 3)
{
return context.Reports.Where(report => report.ReportCreator.DepartmentOfTheUser.Company == CurrentUser.Company).OrderByDescending(report => report.Date).Skip(pageNumber * numberOfRecords).Take(numberOfRecords).ToList();
}
else
if (CurrentUser.Role == 2)
{
return context.Reports.Where(report => report.ReportCreator.Depratment == CurrentUser.Department).OrderByDescending(report => report.Date).Skip(pageNumber * numberOfRecords).Take(numberOfRecords).ToList();
}
else
{
return context.Reports.Where(report => report.CreatedBy == CurrentUser.Id).OrderByDescending(report => report.Date).Skip(pageNumber * numberOfRecords).Take(numberOfRecords).ToList();
}
}