2011-07-18 90 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