我有以下操作方法:-
public ActionResult RackServer(int id) {
var servers = repository.AllFindRack_Servers(id).ToList();
var IT360IDs = servers.Select(a => a.Technology.IT360ID.Value).ToArray();
return PartialView("~/Views/Server/_nonPagedServerTable.cshtml", servers);
}
它调用以下存储库方法:-
public IQueryable<TMSServer> AllFindRack_Servers(int id)
{
return tms.TMSServers.Where(c => c.RackID == id)
.Include(a => a.OperatingSystem)
.Include(a3 => a3.TMSRack.DataCenter)
.Include(a14 => a14.TMSRack.Technology)
.Include(a6 => a6.TMSVirtualMachines)
.Include(a7 => a7.TechnologyStatu)
.Include(a8 => a8.TechnologyBackUpStatu)
.Include(a9 => a9.TechnologyRole)
.Include(a10 => a10.Technology.TechnologyIPs)
.Include(a11 => a11.TMSServer1.Technology)
.Include(a14=>a14.TMSServers1)
.Include(a12 => a12.TMSSwitches)
.Include(a13 => a13.TMSFirewalls);
}
但我注意到,如果我将我的操作方法中的 .Tolist() 位置更改为:-
public ActionResult RackServer(int id) {
var servers = repository.AllFindRack_Servers(id);
var IT360IDs = servers.Select(a => a.Technology.IT360ID.Value).Tolist().ToArray();
return PartialView("~/Views/Server/_nonPagedServerTable.cshtml", servers);
}
那么将完成对存储库方法的两个查询?谁能解释为什么在同一条语句中使用 .Select 和 .Tolist() 会导致执行两个类似的查询。?
谢谢