I have the following models in my ASP.NET MVC 3 project:
public class Task
{
public int Id { get; set; }
public DateTime CreatedOn { get; set; }
public TaskStatus Status { get; set; }
}
public class TaskStatus
{
public int Id { get; set; }
public string Description { get; set; }
}
For reference, here is my DbContext class:
public class TaskManagerSets : DbContext
{
public DbSet<Task> TaskSet { get; set; }
public DbSet<TaskStatus> TaskStatusSet { get; set; }
}
Then I have a List Action in my TaskController:
TaskManagerSets dbcontext = new TaskManagerSets();
public ActionResult List()
{
var tasks = from tsk in dbcontext.TaskSet.Include("TaskStatusSet")
select tsk;
return View(tasks.ToList());
}
Finally I have the Task List View:
@model IEnumerable<TaskManager.Models.Task>
<ul>
@foreach (var tsk in Model)
{
<li>@tsk.Id | @tsk.CreatedOn | @tsk.Status.Description</li>
}
</ul>
When I execute my project I get the following error:
A specified Include path is not valid. The EntityType 'CodeFirstNamespace.Task' does not declare a navigation property with the name 'TaskStatus'.
The problem is definitely on the Include("TaskStatusSet")
but how should I fix this?