title: DataBinder.Eval returns null, although the field is populated
body: <p>I am having trouble displaying an object field of one of my entities in an asp.net application. <code>DataBinder.Eval</code> returns <code>Nothing</code> for some reason.</p>
  
  <p>I have 2 classes as follows:</p>
  
  <pre><code>Public Class Bench
      &lt;ScaffoldColumn(False), StringLength(50), Key&gt; _
      Public Property Code() As String
  
      &lt;Required&gt; _
      Public Property Type() As BenchType
  
      &lt;Required, StringLength(50)&gt; _
      Public Property Name() As String
  
      ...
  End Class
  
  Public Class BenchType
      &lt;ScaffoldColumn(False), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)&gt; _
      Public Property ID() As Integer
  
      &lt;Required, StringLength(50)&gt; _
      Public Property Name() As String
  
      ...
  End Class
  </code></pre>
  
  <p>I am trying to display the <code>Bench</code> entities in a <code>GridView</code> as follows (with a properly implemented <code>ObjectDataSource</code> <code>odsBenches</code>):</p>
  
  <pre><code>&lt;asp:GridView ID="grwBenches" runat="server" DataSourceID="odsBenches"
      DataKeyNames="Code,Type,Name" AutoGenerateColumns="false"&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField HeaderText="Code"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label id="lblCode" runat="server" Text='&lt;%# Bind("Code")%&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Name"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label id="lblName" runat="server" Text='&lt;%# Bind("Name")%&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Bench Type"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label id="lblBenchType" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "Type.Name")%&gt;'&gt;
                  &lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><code>Code</code> and <code>Name</code> fields are displayed ok, but the <code>Type</code> field is shown as empty, this is the resulting markup from the rendered page:</p>
  
  <pre><code>&lt;table cellspacing="0" rules="all" border="1" id="MainContent_grwBenches" style="border-collapse:collapse;"&gt;
      &lt;tr&gt;
          &lt;th scope="col"&gt;Code&lt;/th&gt;&lt;th scope="col"&gt;Name&lt;/th&gt;&lt;th scope="col"&gt;Bench Type&lt;/th&gt;
      &lt;/tr&gt;&lt;tr&gt;
          &lt;td&gt;
                  &lt;span id="MainContent_grwBenches_lblCode_0"&gt;OK Code&lt;/span&gt;
              &lt;/td&gt;&lt;td&gt;
                  &lt;span id="MainContent_grwBenches_lblName_0"&gt;OK Name&lt;/span&gt;
              &lt;/td&gt;&lt;td&gt;
                  &lt;span id="MainContent_grwBenches_lblBenchType_0"&gt;&lt;/span&gt;
              &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When I step through the code, It appears that <code>&lt;%# DataBinder.Eval(Container.DataItem, "Type.Name")%&gt;</code> returns <code>Nothing</code> but when I check the database, the <code>Type</code> field contains the type code.</p>
  
  <p>What could be the problem?</p>
  
  <p>Edit (DAL code):</p>
  
  <pre><code>Public Function GetBenches() As IQueryable(Of Bench)
      Return _db.BENCHES
  End Function
  </code></pre>
  
  <p>Where <code>_db</code> is the DBContext object.</p>