Include()方法适用于对象列表.但是,如果我需要深入两个级别呢?例如,下面的方法将返回ApplicationServers,其中包含此处显示的包含属性.但是,ApplicationsWithOverrideGroup是另一个容纳其他复杂对象的容器.我也可以在该属性上执行Include()吗?或者我如何才能完全加载该属性?
现在看来,这个方法:
public IEnumerable<ApplicationServer> GetAll()
{
return this.Database.ApplicationServers
.Include(x => x.ApplicationsWithOverrideGroup)
.Include(x => x.ApplicationWithGroupToForceInstallList)
.Include(x => x.CustomVariableGroups)
.ToList();
}
Run Code Online (Sandbox Code Playgroud)
将仅填充Enabled属性(下方),而不填充Application或CustomVariableGroup属性(如下所示).我该如何实现这一目标?
public class ApplicationWithOverrideVariableGroup : EntityBase
{
public bool Enabled { get; set; }
public Application Application { get; set; }
public CustomVariableGroup CustomVariableGroup { get; set; }
}
Run Code Online (Sandbox Code Playgroud)