I have a problem with Include() using Entity Framework. I have two models:
public class Project
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name = "Project Title")]
public string Title { get; set; }
// Some other properties
public int ProjectPropertyId { get; set; }
public ProjectProperty ProjectProperty { get; set; } = new ProjectProperty();
}
and the other table:
public class ProjectProperty
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name = "Published")]
public bool Published { get; set; } = false;
[Required]
[Display(Name = "Code Available")]
public bool CodeAvailable { get; set; } = false;
}
When I save a new entity with those properties, No problem. When I want to retrieve, here the problem is. I can get the Project list, but it doesn't include the Project property Entity. This is the code to get the list:
public async Task<List<Project>> GetProjects()
{
return await _context.Project.Include(p => p.ProjectProperty).ToListAsync();
}
On the break point I get this:
I can't get that entity with Include() but in the database:
I know I did a stupid mistake, but I can't figure it out. any help will be appreciated thank you.