2011-07-18 121 views
4

其我很難解釋這一個,但我希望一些代碼將有助於:的LINQ包含值列表

 var softChannels = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive); 

     var tmpGames = new List<MyCms.Content.Games.Game>(); 
     // Get games only from active game channels 
     foreach (var channel in channels.ByPath("/gameslivecasinodirectcom/game-channels/").Children.Where(c => c.StateProperties.IsActive)) 
     { 
      // QUESTION IS ABOUT THIS LINE 
      tmpGames.AddRange(oGames.AllActive.Where(g => g.StateProperties.Channels.Contains(channel.Guid) && g.GamingProperties.Software.Contains(softChannels))); 
     } 

我想要做的是,如果g.GamingProperties.Software包含softChannels的的GUID的一個,然後添加它。也許不同意見會更好......有什麼建議嗎?

p.s我知道該行不工作,我已經把代碼放在那裏,只是爲了方便理解我需要什麼。

編輯: 我想我已經解決了它:

var softChannels = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid); 

var tmpGames = new List<MyCms.Content.Games.Game>(); 
// Get games only from active game channels 
foreach (var channel in channels.ByPath("/gameslivecasinodirectcom/game-channels/").Children.Where(c => c.StateProperties.IsActive)) 
{ 
    tmpGames.AddRange(oGames.AllActive.Where(g => g.StateProperties.Channels.Contains(channel.Guid) && softChannels.Contains(g.GamingProperties.Software.Trim()))); 
} 

如果有人認爲有點不妥,請讓我知道。

+0

究竟是不是工作,你得到了什麼錯誤? – BrokenGlass

+0

'g.GamingProperties.Software'是什麼類型? – SLaks

+0

字符串(包含一個guid) – Dementic

回答

6

你要檢查是否softChannelsAny()包含:

softChannels.Any(sc => g.GamingProperties.Software.Contains(sc)) 

事實上,你甚至可以編寫

softChannels.Any(g.GamingProperties.Software.Contains) 
+0

您的問題是一個更好的解決方案。 – Dementic