title: Flattening an Entity Framework objectquery result with includes
body: <p>I'm trying to get to grips with Entity Framework and there is one thing that's really tripping me up. It doesn't help that I'm still not totally sure of the terminology, and I'm trying to avoid learning LINQ at the same time, so googling is difficult.</p>
  
  <p>I have two tables, company and addresses with a 1-to-many relationship. If I write the following:</p>
  
  <pre><code>ObjectQuery&lt;Company&gt; companies = queryContext.Companies.Include("Addresses");
  </code></pre>
  
  <p>It looks like I am getting what I want (companies -> Results View[0].Addresses.Count is > 0)</p>
  
  <p>What I'd like to do now is bind the company names and all addresses to a gridview in an ASP.NET application</p>
  
  <pre><code>this.CompaniesGrid.DataSource = companies;
  this.CompaniesGrid.DataBind();
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;asp:GridView runat="server" ID="CompaniesGrid" AllowSorting="true"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="Name" /&gt;
          &lt;asp:BoundField DataField="Address" /&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>This on its own throws an error (<code>A field or property with the name 'Address' was not found on the selected data source</code>) - I think because companies -> Results View[0].Name exists but .Address doesn't (because it's buried in the Addresses relationship). Binding to Addresses.Address doesn't help either.</p>
  
  <p>I found one really ugly workaround at the bottom of <a href="http://forums.asp.net/t/1676291.aspx/1" rel="nofollow">this thread</a> but I would rather avoid it if possible.</p>
  
  <p>Is there any way to 'flatten' my results so that the top level objects provide addess to all included fields?</p>
  
  <p>Any help much appreciated!</p>