I have to query a webservice multiple times to get the following data: - schools - school classes - teachers
The webservice gives the data back as JSON string and I converted them to objects with the help of JSON.Net (I created objects for being used with the deserialization, I took the advice from this answer: How to map JSON to C# Objects):
- class SchoolsRoot
- public School[] Schools
- class School
- public string SchoolName
- public string CountryCode
- public int SchoolId
- class SchoolClassesRoot
- public SchoolClass[] SchoolClasses
- class SchoolClass
- public int SchoolClassId
- public string SchoolClassName
- public DateTime StartDate
- public int ParentId (reference to School)
- class TeachersRoot
- public Teacher[] Teachers
- class Teacher
- public int TeacherId
- public string TeacherFullname
- public string TeacherEmail
- public int ParentId (refernce to a single School Class)
When I query the webservice for the schools, classes and teachers I get all the objects but the objects are not in a hierarchy (teacher->school class->school) e.g. like I would have when using an entity framework data context.
What I would like to have is to have a simple way to get all teachers of a school for example, or get only schools from a specific country code.
My approach would be add properties for this to the object, maybe create some sort of parent container that holds all the data of the 3 "lists" and then iterate over the objects and manually create/set the references to the correct objects according to the "parentId".
The question is, is this a good way to set the references or are there more efficient ways? Is there maybe already some way using the deserialization of JSON.Net (I found nothing like in the documentation)?