title: Comparing the ID's of two Tables ASP.Net MVC
body: <p>I have two tables. </p>
  
  <p>Author Table --- AuthID PK</p>
  
  <p>Contract Table --- AuthID FK</p>
  
  <p>I would like to restrict the Contract View "Author Name" Box to Authors that do not already have Contracts. </p>
  
  <p>I think I could do it with alot more code but I feel like there is a way to do it with a simple query and I am just missing it.</p>
  
  <p>Here is my Code: </p>
  
  <pre><code> public ActionResult Create()
      {
          var contract = new Contract();
  
          var allAuthors = db.Authors.Select(a =&gt; a.AuthID);
          var unusedAuthors = new List&lt;Author&gt;();
          foreach (var auth in allAuthors) {
              unusedAuthors = db.Contracts
                  .Where(a =&gt; a.AuthID.GetHashCode() != auth.GetHashCode())
                  .Select(a =&gt; a.Author).ToList();
          }
  
  
  
  
          ViewBag.AuthID = new SelectList(unusedAuthors, "AuthID", "AuthFirstName");
          return View(contract);
      }
  </code></pre>