我从图中有两个表。对于每个问题我都可以有多个答案。 我希望以json格式按问题ID获取数据,如下所示:
var initialData = [
{question_id: "1", Description: "Danny", Status: "1", answers: [
{ answer_id: "1", description: "AAAAA" },
{ answer_id: "2", description: "Bbbbb" }]
}
];
我使用此代码
var question = db.Questions.FirstOrDefault((p) => p.questionID== id);
return this.Json(question , JsonRequestBehavior.AllowGet);
我得到了这个
var initialData = [
{question_id: "1", Description: "Danny", Status: "1", answers:null
}
];
你能帮我解决一下吗?
答案 0 :(得分:2)
请你试试。
var question = db.Questions.Include("Answer").FirstOrDefault((p) => p.questionID== id);
查看ado.Net blog