I am working a bit backwards here and trying to create a web api from a provided JSON example that is being used for the front end. Here is the JSON format.
{"Sections": [{
"sectionID":"1",
"sectionOrder":1,
"sectionName":"Approach",
"sectionText": "",
"sectionContent": [{
"contentID": "1",
"contentTitle": "Definition",
"contentText": "Lorem Ipsum",
"contentImage": ""
},
{
"contentID": "2",
"contentTitle": "Vision",
"contentText": "Lorem Ipsum",
"contentImage": "image2.jpg"
}]
}]}
I have created 2 tables (Section & Section Content linked by SectionContentID) and added the tables as models using entity framework. I have then created a controller to return the section table but now is where I am stuck on how to join the section content data into 1 JSON response.
My controller just looks like this:
public IQueryable<Sections> GetSections()
{
//how do I add db.SectionsContent to Sections linked by the sectionContentID field?
return db.Sections;
}
SectionContentthat would be an enumeration ofSectionContentso normally the serializer can just serialize the response in one go and get the json you're looking for.