I am trying to query and have the navigational property (the list) return with the correct number of items in it. Currently what I am doing, the list is always empty (Case_Users property in Case object for the example below) when it should not be.
I have these classes:
public class Case
{
public Case()
{
Create_Date = DateTime.Now;
}
[Key]
public int Id { get; set; }
[MaxLength(1000)]
public string CaseNumber { get; set; }
public ICollection<Case_Users> Case_Users { get; set; } = new List<Case_Users>();
}
public class Case_Users
{
public Case_Users()
{
Create_Date = DateTime.Now;
}
[Key]
public int Id { get; set; }
[ForeignKey("Case")]
public int CaseID { get; set; }
public Case Case { get; set; }
public string Role {get; set;}
}
I want to make it so that I can query using the method syntax, starting with the Case and using its navigational property to get the data from its Case_Users navigational property entries, like this:
var query = _context.Case.Include(c => c.Case_Users).ToList();
I am getting simply my list object returned, but the Case_Users list object is empty. Even though it should not be.
Is it possible to query based on the navigational property, and if so what is the syntax?