title: Getting specific user data in ASP.NET MVC with Entity Framework
body: <p>So im trying to get a list of data recorded in the database for that specific user who's logged in. This should be an easy task, but I cant get it to work.</p>
  
  <p>Here's what I tried and I get the following errors:</p>
  
  <p>"The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties."</p>
  
  <p>Here's some code:</p>
  
  <p>Model:</p>
  
  <pre><code>public partial class TimesheetEntry
      {
          [Key]
          [Column(Order = 0)]
          [DatabaseGenerated(DatabaseGeneratedOption.None)]
          public int UserId { get; set; }
  
          [Key]
          [Column(Order = 1)]
          [StringLength(50)]
          public string ProjectId { get; set; }
  
          [Key]
          [Column(Order = 2, TypeName = "date")]
          public DateTime EntryDate { get; set; }
  
          public decimal HoursWorked { get; set; }
  
          public virtual Project Project { get; set; }
  
          public virtual User User { get; set; }
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model IEnumerable&lt;Aviato.Models.TimesheetEntry&gt;
  
  @{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create", "Create")
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.UserId)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Project.ProjectName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.EntryDate)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.HoursWorked)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.UserId)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Project.ProjectName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.EntryDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.HoursWorked)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id=item.UserId }) |
                  @Html.ActionLink("Details", "Details", new { id=item.UserId }) |
                  @Html.ActionLink("Delete", "Delete", new { id=item.UserId })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  
  &lt;/table&gt;
  &lt;div&gt;
      @Html.ActionLink("Index", "Index", "User")
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class TimesheetEntryController : Controller
      {
          private readonly AviatoModel _db = new AviatoModel();
  
          public ActionResult Index()
          {
              var userId = (int)Session["userId"]; // I have made a breakpoint and confirm that the user get it's unique Id.
              var user = _db.Users.Find(userId);
              var timesheetentries = _db.TimesheetEntries.Include(t =&gt; t.Project).Include(t =&gt; t.User == user);
  
              return View(timesheetentries.ToList());
          }
  </code></pre>
  
  <p>It's easy to get all the records in the database just by deleting the first two rows of code in the controller, but that's not my goal here.</p>
  
  <p>Please help!</p>