【发布时间】:2011-10-17 08:13:15
【问题描述】:
我有两个包含 guid 的列表:
var activeSoftware = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid);
var activeChannels = channels.ByPath("/game-channels/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid);
还有另一个游戏列表:
List<MyCms.Content.Games.Game> games = new List<MyCms.Content.Games.Game>();
游戏对象有两个可以使用的属性:
game.gamingproperties.software - 包含软件的 guid
game.stateproperties.channels - 逗号分隔的 guid 列表
是的,我知道在字段中保存逗号分隔值并不好, 但我目前无法更改它(它已经在 40 多个网站上运行)
我想要做的是选择软件处于活动状态的所有游戏(通过比较 softwarelist 和 game.gamingproperties.software)并且它们出现的频道处于活动状态(通过检查 game.stateproperties.channels 是否包含 @ 987654328@指导)
最初,我是这样做的:
foreach (var channel in activeSoftware)
{
foreach (var match in oGames.AllActive.Where(g => !string.IsNullOrEmpty(g.GamingProperties.UrlDirectGame) && g.GamingProperties.Software.Contains(channel) && g.StateProperties.Channels.Split(',').Intersect(activeChannels).Any()))
{
games.Add(match);
}
}
但我确信我可以摆脱那些讨厌的 foreach 并只使用 linq。
【问题讨论】: