title: Add temporary property to list of objects
body: <p>I have 3 models</p>
  
  <pre><code>public class Payroll
  {
      public int ID { get; set; }
  
      public DateTime Date { get; set; }
  
      public int PayCategoryID { get; set; }
  
      public virtual PayCategory PayCategory { get; set; }
  }
  </code></pre>
  
  <p>this one: </p>
  
  <pre><code>public class PayCategory
  {
      public int ID { get; set; }
  
      public string PayScenario { get; set; }
  
      public int PayGroupID { get; set; }
  
      public virtual PayGroup PayGroup { get; set; }
  }
  </code></pre>
  
  <p>and this one:</p>
  
  <pre><code>public class PayGroup 
  {
      public int ID { get; set; }
  
      public string Label { get; set; }
  
      public string Description { get; set; }
  
      public string EntryType { get; set; }
  
  }
  </code></pre>
  
  <p>If I create a List of Payroll I will only get a list of Payroll objects with 4 properties each. 
  I want a list of , where each Payroll object will have the fields
         Date, PayScenario, Label, Description, and EntryType. I know these can be easily obtained by </p>
  
  <pre><code>    Payroll.PayCategory.PayScenario
      Payroll.PayCategory.PayGroup.Label
  </code></pre>
  
  <p>etc. </p>
  
  <p>But I am exporting these to an excel document using this generic method:</p>
  
  <pre><code>      public static void Export(List&lt;T&gt; data, string name, Controller controller) 
      {
          XLWorkbook workbook = new XLWorkbook();
          var worksheet = workbook.Worksheets.Add(name);
          worksheet.Cell(1, 1).InsertTable(data); 
          controller.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheet.sheet";
          controller.Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", name.Replace(" ", "_")));
          using (MemoryStream memoryStream = new MemoryStream())
          {
              workbook.SaveAs(memoryStream);
              memoryStream.WriteTo(controller.Response.OutputStream);
              memoryStream.Close();
          }
          controller.Response.End();
  
      }
  </code></pre>
  
  <p>I call from controller like this:            </p>
  
  <pre><code>    public ActionResult ExportData()
      {
          var payrolls = (List&lt;Payroll&gt;)Session["payrolls"];
          ExportToExel&lt;Payroll&gt;.Export(payrolls, "Payroll", this);
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>And the results of course give me a simple table with only the value Date in it, (plus some other trash columns like System [...] PayCategory)</p>
  
  <p>Ultimately, I want the properties of these 3 models to be merged (excluding ID's) to give me a single list that I can pass on to the ExportData method. As in, is there a way to add a column to a list of objects? Something similar to </p>
  
  <pre><code>        for(int i = 1; i&lt;payrolls.Count; i++)
                payrolls[i].Add.(payrolls[i].PayCategory.PayScenario);  
  </code></pre>
  
  <p>which of course, doesn't work.
  Please don't ask why I don't simply have one model instead of these 3. It's not an option unless I want to hard code values. </p>
  
  <p>Thanks</p>