4

我很难解释这一点,但我希望一些代码会有所帮助:

        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的Guids之一,然后添加它。也许不同的方法会更好......有什么建议吗?

ps 我知道那条线不工作,我把代码放在那里只是为了便于理解我需要什么。

编辑:我想我已经解决了:

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())));
}

如果有人发现有问题,请告诉我。

4

1 回答 1

6

您要检查是否Any()包含softChannels

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

事实上,你甚至可以写

softChannels.Any(g.GamingProperties.Software.Contains)
于 2011-07-18T15:36:25.823 回答