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 之一,则添加它。也许不同的方法会更好......有什么建议吗?
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())));
}
如果有人发现有什么问题,请告诉我。
its hard for me to explain this one, but i hope some code will help:
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)));
}
what i want to do is, if g.GamingProperties.Software
contains one of the Guids of softChannels, then add it. maybe a diffrent approace will be better... any suggestions ?
p.s i know that line is not working, i have put the code there only for easy understanding what i need.
EDIT:
i think i have resolved it:
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())));
}
if anyone sees something wrong with that, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要检查是否包含
softChannels
的Any()
:事实上,您甚至可以编写
You want to check whether
Any()
of thesoftChannels
are contained:In fact, you can even write