title: ASP.NET Entity Framework ListView entitydatasource Multiple Table, Unable to Retrieve Data
body: <p>My database relationship is as follow; </p>
  
  <p>Country -> Region -> City -> Medical -> MedicalServices all of them are connected to each other as one to many.</p>
  
  <p>Here is the listview and entitydatasource which works as intended without any problem. The problem is with the code behind.</p>
  
  <pre><code> &lt;asp:ListView ID="lvMainContent" runat="server" 
      DataKeyNames="MedicalID"&gt;
  &lt;LayoutTemplate&gt;
      &lt;ul ID="itemPlaceholderContainer" runat="server" 
          style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;
          &lt;li runat="server" id="itemPlaceholder" /&gt;
      &lt;/ul&gt;
  &lt;div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;"&gt; 
  &lt;/div&gt;
  &lt;/LayoutTemplate&gt;
      &lt;ItemSeparatorTemplate&gt;
          &lt;br /&gt;
      &lt;/ItemSeparatorTemplate&gt;
  &lt;ItemTemplate&gt;
      &lt;li style="background-color: #DCDCDC;color: #000000;"&gt;Medicals:
         &lt;br /&gt;
          MedicalName:
          &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("medicalName") %&gt;' /&gt;
          &lt;br /&gt;
  
          &lt;br /&gt;
          CityName:
          &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Eval("City.CityName") %&gt;' /&gt;
          &lt;br /&gt;
          &lt;br /&gt;
      &lt;/li&gt;
  
  &lt;/ItemTemplate&gt;
  
  &lt;/asp:ListView&gt;
  &lt;asp:EntityDataSource ID="lvMainContentDataSource" runat="server"
  ConnectionString="name=EntitiesMedical" 
      DefaultContainerName="EntitiesMedical"  EntitySetName="Medicals"  
  
      EnableFlattening="False"&gt;
  
  &lt;/asp:EntityDataSource&gt;
  </code></pre>
  
  <p>And Here is the Code Behind which is connected to "Search" button actually Code Behind and ASP side seem identical to me but when I press the Search button an error is thrown, I add it after the code behind.</p>
  
  <pre><code>protected void SearchButton_Click(object sender, EventArgs e)
      {          
  
         using(Entity.EntitiesMedical em = new Entity.EntitiesMedical())
         {
  
             var result = from m in em.Medicals
  
                          where m.City.CityName == "Düsseldorf"
  
                          select new
                          {
                             m.MedicalID,
                             m.medicalName,
                             m.City.CityName
                          };
  
             EntityDataSource eds = new EntityDataSource();
             eds.ConnectionString = "name=EntitiesMedical";
             eds.DefaultContainerName = "EntitiesMedical";
             eds.EntitySetName = "Medicals";
  
             lvMainContent.DataSource = result.ToList();
             lvMainContent.DataBind();
  
         }          
  
      }
  </code></pre>
  
  <p>DataBinding: '&lt;>f__AnonymousType5`3[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'City'.</p>
  
  <p>Any help would be appreciated. I am confused with Include property actually I don't need it at all I guess.</p>