my current project is based on Entity Framwork code-first. I have three types: Task, TaskType and Module.
public class Task
{
public int ID {
I'm new to entity framework but I just ran into the same issue, where my foreign key property was populated but the navigation object was null, with code like:
public class EntryRecord
{
[Key]
public int Id { get; set; }
}
public class QueueItem
{
[Key]
public int Id { get; set; }
public int EntryRecordId { get; set; }
[ForeignKey("EntryRecordId")]
public EntryRecord EntryRecord { get; set;}
}
Setting the navigation property to virtual fixes the problem and enables lazy loading :
[ForeignKey("EntryRecordId")]
public virtual EntryRecord EntryRecord { get; set;}