2012-03-23 86 views
0

我有3個表,團隊(id,name)player(id,teamid,name)playerdetail(id,playerid,height,weight),團隊和玩家之間的關係是一對一很多玩家和playerdetail之間的關係是一對一的。如何選擇集合類型導航屬性的值

我想用急切的加載來加載所有信息並打印出高於2米的玩家的名字。

我寫下面的代碼,

using (var context = new TestEntities()) 
      { 
       var query = from t in context.Teams.Include("Players.PlayerDetails") select t; 
       foreach (var v in query) 
       { 
        Console.WriteLine(v.Players.Any(x => x.PlayerDetails.Any(y => y.Height > 200))); 
       } 
       Console.Read(); 
      } 

它打印出來只有真與假,我怎麼可以修改它,讓它打印出球員的名字? 在此先感謝

回答

1

爲什麼不通過context.Players像下面那樣查詢玩家?

 using (var context = new TestEntities()) 
     { 
      var query = context.Players.Include("Team").Include("PlayerDetails") 
          .Where(p => p.Height > 200); 
      foreach (var v in query) 
      { 
       Console.WriteLine(v.Name); 
      } 
      Console.Read(); 
     }