title: Joining Tables Using Entity Framerwork Fluent Syntax
body: <p>I have tables Table1, Table2, Table3 and so on. To handle auditing, I use Audit table with the following fields Id, Username, ChangeTime, ChangeType, TableName and TableRecordId.</p>
  
  <p>To obtain all records in Table1 joined with Audit on Table1.Id = Audit.TableRecordId where Username is "jdoe" for example, I have the following:</p>
  
  <pre><code>var results = db.Table1s
              .Join(db.Audits.Where(a =&gt; a.Username == "jdoe"),
              t =&gt; t.Id,
              a =&gt; a.RecordId,
              (t, a) =&gt; new { Table1 = t, Audit = a });
  </code></pre>
  
  <p>But when I run it I get the following error:</p>
  
  <pre><code>The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[&lt;&gt;f__AnonymousType1`2[SampleApp.Models.Table1,AuditLibraryContext.Models.Audit]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[AuditTrackerSample.Models.Table1]'.
  </code></pre>
  
  <p>Got it working I ended up with the following code:</p>
  
  <pre><code>var results = db.Table1s
              .Join(db.Audits.Where(a =&gt; a.Username == "jdoe"),
              t =&gt; t.Id,
              a =&gt; a.RecordId,
              (t, a) =&gt; t);
  </code></pre>