Breeze navigation properties not loaded
-
21-12-2019 - |
Question
I have the following many to many model between Project
and UserProfile
entities. As many to many relationships is not supported in Breeze yet, I am exposing the middle entity ProjectMember
as well. So the server side code looks like the following:
public class Project
{
public int ProjectId { get; set; }
public String Name { get; set; }
public virtual List<ProjectMember> ProjectMembers { get; set; }
}
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public virtual List<ProjectMember> ProjectMembers { get; set; }
}
public class ProjectMember
{
public int ProjectId { get; set; }
[ForeignKey("ProjectId")]
public Project Project { get; set; }
public int UserId { get; set; }
[ForeignKey("UserId")]
public UserProfile UserProfile { get; set; }
}
The metadata returned from the server seems to be the right one:
The navigation property seem to be properly sent out by the server.
When I request a project from the client by doing:
var query = entityQuery.from("Projects")
.where('projectId', '==', projectId)
.expand("projectMembers");
The returned JSon data is the one expected:
However, the Project.ProjectMembers
navigation property is not properly constructed on the client side as you see from the screenshot below:
I went through the tutorials, the breeze documentation, the SO questions related to navigation properties and I still don't see what I am doing wrong.
Question:
Given the information above, why is Breeze not loading the ProjectMembers
navigation property?
Solution
I would start by checking the EntityManager's metadataStore to make sure that the ProjectMember entityType can be found. You can do this after your first query via
var projectMemberType = myEntityManager.metadataStore.getEntityType("ProjectMember");
If the projectMemberType is not found then the problem has to do with the metadata not being brought down correctly.
Another possibility, have you defined a key for the ProjectMember type ( presumably a two part key)?