我在这里工作有点倒退,并尝试从提供的用于前端的 JSON 示例创建一个 web api。这是 JSON 格式。
{"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"
}]
}]}
我创建了 2 个表(由 SectionContentID 链接的部分和部分内容)并使用实体框架将这些表添加为模型。然后我创建了一个控制器来返回部分表,但现在我陷入了如何将部分内容数据连接到 1 个 JSON 响应的问题。
我的控制器看起来像这样:
public IQueryable<Sections> GetSections()
{
//how do I add db.SectionsContent to Sections linked by the sectionContentID field?
return db.Sections;
}
噜噜哒
明月笑刀无情
相关分类