title: Using Linq to get records that have specific foreign key
body: <p>I'm trying get all records from a table that have a specific foreign key but I'm struggling to get linq to return anything useful.</p>
  
  <p><strong>Post Model</strong></p>
  
  <pre><code>public class Post
  {
      //... irrelevant properties
      [ForeignKey("Category")]
      public int CategoryId;
      public virtual Category Category { get; set; }
  }
  </code></pre>
  
  <p><strong>my dbo.Posts table</strong></p>
  
  <p><img src="https://i.stack.imgur.com/3ax8l.png" alt="enter image description here"></p>
  
  <p><strong>What I've tried</strong></p>
  
  <p>I've tried several variations of the following:</p>
  
  <pre><code>//id = 7
  
  using (UnitOfWork uwork = new UnitOfWork())
  {
      var post = uwork.PostRepository.GetAll().Where(c =&gt; c.CategoryId == id);
  
  }
  </code></pre>
  
  <p>This only returns "Non-Public members", which doesn't contain anything useful.</p>
  
  <p><img src="https://i.stack.imgur.com/LoT0U.png" alt="enter image description here"></p>
  
  <h2>Question</h2>
  
  <p>How could I modify my linq query to return all posts that have a specific Foreign Key id?</p>
  
  <hr>
  
  <p><em>updates</em></p>
  
  <h2><a href="https://gist.github.com/codebeaulieu/610c09e67b5c1c4343f4" rel="nofollow noreferrer">here's my repository</a></h2>