title: Get results matching a list of Ids using Linq
body: <p>I am trying to get the list of gameIds that satisfy all the genreIds included in a a <code>List&lt;int&gt;</code>. </p>
  
  <p>The tables (partial):</p>
  
  <p>editorial_list:</p>
  
  <ul>
  <li>game_id</li>
  <li>content</li>
  </ul>
  
  <p>game_genres (game can belong to several genres):</p>
  
  <ul>
  <li>id</li>
  <li>game_id</li>
  <li>genre_id</li>
  </ul>
  
  <p>I need to get the list of the game Ids of games that exists for all the <code>genre_id</code>'s in the game_genres table.</p>
  
  <p><strong>For example:</strong></p>
  
  <p>The list of <code>genre_id</code>'s includes genre 2 and 3.</p>
  
  <p>If Game Id = 14 exists in <code>game_genres</code> table for both <code>genre_id</code> = 2 and <code>genre_id</code> = 3. So it will be included in the final results.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> // get the list of game_id's that have an editorial
   var editorialList = (from ee in db.editorials where ee.is_enabled == true select new {
       game_id = ee.game_id
   }).ToList();
  
  // Produce a list of the games in the editorials and their genre Ids that the belong to
   var gameAndGenres = (from el in editorialList join gg in db.game_genres
    on el.game_id equals gg.game_id
  
       select new {
           game_id = el.game_id,
               genre_id = gg.genre_id
       }
   );
  
   var res = gameAndGenres.Where(
    x =&gt; x.genres.Contains(x.genre_id)) == genres.Count; // stuck here
  </code></pre>
  
  <p><strong>The end results</strong> should be a unique list of game_id's, that each game in the list <strong>belongs to all</strong> the genres that was listed in the genres <code>List&lt;int&gt;</code>.</p>
  
  <p>I created several steps to help me understand the query, but it might be able to be solved in one line, I just wasn't able to solve it.</p>
  
  <p>Update: This is a new code that I'm trying.</p>
  
  <pre><code> var res = gameAndGenres.GroupBy(x =&gt; x.game_id)
    .Select(g =&gt; new {
     game_id = g.Key,
     genreIds = g.Select( c =&gt; c.genre_id)
  
     });
  
     var res2 = res.Where(x =&gt; genres.Intersect(x.genreIds).Count()
    == genres.Count()).ToList();
  </code></pre>