title: Export iQueryable of complex objects to Excel
body: <p>We have some code that exports data from a database to Excel and it works well.</p>
  
  <p>The main problem is we use a DB view to gather all our data.  This creates the issue of having a sizable view as we have multiple types of objects of which we export.</p>
  
  <pre><code>class Event
    int id
    string title
    List&lt;EventDate&gt; Dates
    string desc
  
  class EventDate
    DateTime start
    DateTime end
    List&lt;EventLocation&gt; Locations
  
  class EventLocation
    string address
    string city
    string zip
  
  class Birthday : Event
    int balloonsOrdered
    string cakeText
  
  class Meeting : Event
    string Organizer
    string Topic
  </code></pre>
  
  <p>So, above is the model.  <code>Birthday</code> and <code>Meeting</code> inherit from <code>Event</code> and all <code>Event</code> objects have a list of <code>EventDate</code> objects.  Each <code>EventDate</code> object has a start date, end date and a list of <code>Location</code> objects.</p>
  
  <p>Our goal is to find a dynamic way to get data from the DB to an Excel doc.  We'd rather not maintain a massive view in the database (as we'll add more event types eventually).  </p>
  
  <p>I'm not all that familiar with .NET's XML capabilities, but the solution we are using now uses OpenXML and the code makes sense.</p>