我想解釋一下這個問題,因爲我認爲這個問題沒有得到解答。
基於例如從這裏: 的IQueryable> prodQuery = 從db.Products PROD 組由prod.CategoryID刺到分組 選擇分組;
foreach (IGrouping<Int32, Product> grp in prodQuery)
{
Console.WriteLine("\nCategoryID Key = {0}:", grp.Key);
foreach (Product listing in grp)
{
Console.WriteLine("\t{0}", listing.ProductName);
}
}
如果表產品具有表T_Category一個外鍵關係,訪問類別的唯一方法是通過db.Product.T_Category.CategoryID。如果是這種情況,是否會包含能夠獲取T_Category中其他信息的工作,例如T_Category.CategoryName?
的IQueryable> prodQuery = 從db.Products.include( 「T_Category」)由prod.T_Category.CategoryID 組督促刺到分組 選擇分組;
foreach (IGrouping<Int32, Product> grp in prodQuery)
{
Console.WriteLine("\nCategoryID Key = {0}:", grp.Key);
foreach (Product listing in grp)
{
Console.WriteLine("\t{0}", listing.ProductName);
Console.WriteLine("\t{0}", listing.T_Category.CategoryID);
Console.WriteLine("\t{0}", listing.T_Category.CategoryName);
}
}
來源
2010-05-26 10:50:47
Nap