我尝试使用Eagerly Loading来加载所需的数据。但它不起作用。当我使用时:
Configuration.LazyLoadingEnabled = True;
它加载了所有关系表,但是我想限制它,所以我将true更改为false并尝试加载关系,但是没有加载。
这是我的代码:
public CommonsController(ICreditApplicationsContext creditApplicationsContext)
{
if(creditApplicationsContext != null)
{
this.creditApplicationsContext = creditApplicationsContext;
creditApplicationsContext.Years.Include("Makes");
creditApplicationsContext.Makes.Include("Models");
creditApplicationsContext.Models.Include("Trims");
}
else
{
this.creditApplicationsContext = new CreditApplicationsContext();
}
this.creditApplicationsRepository = new CreditApplicationsRepository(this.creditApplicationsContext);
}
我将此代码放在使用Context的页面中,我尝试将其放在Context中但同样的问题。
答案 0 :(得分:1)
您没有将调用结果分配给变量:
试
var Years = creditApplicationsContext.Years.Include("Makes").ToList();
您可以在该行上设置断点并逐步执行,现在应填充Years
并包含Makes
个对象。