Linq2Entities 有 预先加载 这个概念,看下面的例子:
using (Entities entities = new Entities())
{
var query = (from o in entities.Orders.Include("Customers")
where o.ShipCountry == "USA"
select o);
foreach (Orders order in query)
Console.WriteLine(order.OrderID + " --- " +
order.Customers.CompanyName);
}
通过entities.Orders.Include("Customers") 中的 Include("tableName") 来预先加载数据。