title: Rewriting LINQ to SQL
body: <p>I have a LINQ query that I need to rewrite in TSQL to understand why it's pulling duplicate data. However, I'm not able to actually run the code so I have to do it by just looking at the LINQ.</p>
  
  <p>Since you can use JOIN in LINQ, I'm not sure what's going on with these 2 FROMs.</p>
  
  <p>When I try to write a query to pull this data, I am not getting any duplicates -- yet when the code runs, it is failing on a SingleOrDefault call for duplicate data.</p>
  
  <pre><code>var myQ = from T in context.TableModels
            .Where(T =&gt; T.ID == 'ID')
          from C in context.ChairModels
           .Where(C =&gt; C.TableID == T.ID &amp;&amp; C.TableKey == T.TableKey)
         .DefaultIfEmpty()
      select new
       {
         ...
        };
  </code></pre>
  
  <p>SingleOrDefault is called elsewhere and uses a key to select the 1 record. The database only has this key 1 time, yet SingleOrDEfault is failing for there being more than 1 item returned.</p>