title: SQL to LINQ to get all records that match all values
body: <p>How can I transform this query to linq c# code:</p>
  
  <pre><code>SELECT k1.Ad_Id FROM KeywordAdCategories k1, KeywordAdCategories k2
  WHERE k1.Keyword_Id =  (SELECT Id FROM keywords WHERE name = 'ALFA')
  AND k2.Keyword_Id = (SELECT Id FROM keywords WHERE name = '145')
  AND k1.Ad_Id = k2.Ad_Id
  </code></pre>
  
  <p>The ideia is to build a dynamic query based in the number of keywords that can be N (in the example they are 2: ALFA and 145)</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>KeywordAdCategory Model:</p>
  
  <pre><code>public class KeywordAdCategory
  {
      [Key]
      [Column("Keyword_Id", Order = 0)]
      public int Keyword_Id { get; set; }
  
      [Key]
      [Column("Ad_Id", Order = 1)]
      public int Ad_Id { get; set; }
  
      [Key]
      [Column("Category_Id", Order = 2)]
      public int Category_Id { get; set; }
  }
  </code></pre>
  
  <p>Keyword Model:</p>
  
  <pre><code>public class Keyword
  {
      // Primary properties
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>If I had 5 Keywords I would get:</p>
  
  <pre><code>SELECT k1.Ad_Id FROM KeywordAdCategories k1, KeywordAdCategories k2, KeywordAdCategories k3, KeywordAdCategories k4, KeywordAdCategories k5
  WHERE k1.Keyword_Id =  (SELECT Id FROM keywords WHERE name = 'KEYWORD1')
  AND k2.Keyword_Id = (SELECT Id FROM keywords WHERE name = 'KEYWORD2')
  AND k1.Ad_Id = k2.Ad_Id
  AND k3.Keyword_Id =  (SELECT Id FROM keywords WHERE name = 'KEYWORD3')
  AND k2.Ad_Id = k3.Ad_Id
  AND k4.Keyword_Id =  (SELECT Id FROM keywords WHERE name = 'KEYWORD4')
  AND k3.Ad_Id = k4.Ad_Id
  AND k5.Keyword_Id =  (SELECT Id FROM keywords WHERE name = 'KEYWORD5')
  AND k4.Ad_Id = k5.Ad_Id
  </code></pre>