2011-07-18 2 views
4

il est difficile pour moi d'expliquer celui-ci, mais j'espère un code vous aidera:Linq Contient la valeur dans la liste

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

ce que je veux faire est, si g.GamingProperties.Software contient l'un des Guids de softChannels, puis ajoutez-le. peut-être qu'une approche différente sera meilleure ... des suggestions?

p.s je sais que la ligne ne fonctionne pas, j'ai mis le code là seulement pour comprendre facilement ce dont j'ai besoin.

EDIT: je pense que je l'ai résolu, il:

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

si quelqu'un voit quelque chose de mal à cela, s'il vous plaît laissez-moi savoir.

+0

exactement ce qui ne fonctionne pas et quelle erreur que vous obtenez? – BrokenGlass

+0

De quel type est 'g.GamingProperties.Software'? – SLaks

+0

string (contenant un guid) – Dementic

Répondre

6

Vous voulez vérifier si Any() du softChannels sont contenus:

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

En fait, vous pouvez même écrire

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

Votre solution est plus agréable. – Dementic

Questions connexes