Your data model is incorrect. Our data models in code often do not exactly follow that of our database structure, especially when the data is hierarchical... remember, our tables are normalised, whereas there is no benefit from doing this in code. So your database table may have the foreign key Id of a Class in a child table, but in a business model, this is usually implemented as a parent class that has a collection of children. So in your case, your parent class should look more like this:
public class SchoolClass
{
public SchoolClass(List<Pupil> pupils)
{
this.Pupils = pupils;
}
public List<Pupil> Pupils { get; set; }
...
}
There is no need to define a 'weak entity' or 'joining table' in code. Whereas your problem before was that your parent SchoolClass
class did not have a collection of Pupil
s, now it does, so try your HierarchicalDataTemplate
again.