title: Combining data from multiple tables to display in the MVC View
body: <p>I have two separate models in my MVC project</p>
  
  <pre><code>[Table("Table1")]   
   public class Companies : IEnumerable
   {      
       [Key]
      public double ID { get; set; }
      public System.Guid Key { get; set; }
      public string Name { get; set; }
      public string Company { get; set; }
      public string Industry { get; set; }
      public string Rank{ get; set; }
  
  
      public IEnumerator GetEnumerator()
      {
          yield return this.ID;
          yield return this.Key;
          yield return this.Name;
          yield return this.Company;
          yield return this.Industry;
          yield return this.Rank;
  
      }
   }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>[Table("Table2")]
   public class Registration : IEnumerable
   {
      [Key]
      public System.Guid Key { get; set; }
      public string FieldValue{ get; set; }
      public DateTime StartDate { get; set; }
      public DateTime EndDate { get; set; }
  
  
      public IEnumerator GetEnumerator()
      {
          yield return this.Key;
          yield return this.FieldValue;
          yield return this.StartDate;
          yield return this.EndDate;
  
       }
    }
  </code></pre>
  
  <p>I need to display a combination of data in my view:</p>
  
  <pre><code>SELECT t2.FieldValue, t1.Name, t1.Company, t1.Industry, t1.Rank 
  FROM Table1 as t1 INNER JOIN Table2 as t2 ON t1.Key=t2.Key
  </code></pre>
  
  <p>I created the following Context class:</p>
  
  <pre><code>public class TablesContext: DbContext
  {
      public DbSet&lt;Companies&gt; companies { get; set; }
      public DbSet&lt;Registration&gt; registration { get; set; }
  }
  </code></pre>
  
  <p>Now I can pass the data for companies from the controller to the view using the following code:</p>
  
  <pre><code>private TablesContext tc = new TablesContext();
   var comps = (from c in tc.companies                                 
                      join r in tc.registry
                      on c.Key equals r.Key
        select new { FieldValue=r.FieldValue, Name=c.Name, Company=c.Company,Industry=c.Industry, Rank=c.Rank});
   return View(comps);
  </code></pre>
  
  <p>Now I am a bit stuck trying to make TablesContext class enumerable and loop through the result set in the View. Can anyone point me in the right direction?</p>