title: entity framework - getting null exception using foreign key
body: <p>Having some trouble with what should be a very simple scenario. For example purposes, I have two tables:</p>
  
  <p>-Users
  -Comments</p>
  
  <p>There is a one-to-many relationship set up for this; there is a foreign key from <code>Comments.CommentorID</code> to <code>Users.UserID</code>. When I do the LINQ query and try to bind to a <code>DataList</code>, I get a null exception. Here is the code:</p>
  
  <pre><code>FKMModel.FKMEntities ctx = new FKMModel.FKMEntities();
          IQueryable&lt;Comment&gt; CommentQuery =
              from x in ctx.Comment
              where x.SiteID == 101 
              select x;
          List&lt;Comment&gt; Comments = CommentQuery.ToList();
          dl_MajorComments.DataSource = Comments;
          dl_MajorComments.DataBind();
  </code></pre>
  
  <p>In the ASPX page, I have the following as an ItemTemplate (I simplified it and took out the styling, etc, for purposes of posting here since it's irrelevant):</p>
  
  <pre><code>&lt;div&gt;
     &lt;%# ((FKMModel.Comment)Container.DataItem).FKMUser.Username %&gt;
     &lt;%# ((FKMModel.Comment)Container.DataItem).CommentDate.Value.ToShortDateString() %&gt;
     &lt;%# ((FKMModel.Comment)Container.DataItem).CommentTime %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The exception occurs on the first binding (<code>FKMUser.Username</code>).  Since the foreign key is set up, I should have no problem accessing any properties from the Users table. Intellisense set up the <code>FKMUser</code> navigation property and it knows the properties of that foreign table. What is going on here???</p>