【发布时间】:2016-10-16 14:42:48
【问题描述】:
我有这个模型:
议程
public class Agenda
{
[Key]
public int AgendaID { get; set; }
public DateTime data { get; set; }
public List<Agendamento> agentamentos { get; set; }
public string status { get; set; }
}
议程
public class Agendamento
{
[Key]
public int AgendamentoID { get; set; }
public Clientes cliente { get; set; }
public DateTime data { get; set; }
public string botijao { get; set; }
public int quantidade { get; set; }
public string veiculo { get; set; }
public string status { get; set; }
}
我的 DAO:
议程DAO
public class AgendaDAO
{
private ApplicationDbContext db = new ApplicationDbContext();
public List<Agenda> Listar()
{
return db.Agenda.Include(a => a.agentamentos).ToList();
}
}
DAO 议程
public class AgendamentoDAO
{
private ApplicationDbContext db = new ApplicationDbContext();
public List<Agendamento> Listar()
{
return db.Agendamentoes.Include(a => a.cliente).ToList();
}
}
在我的 ApiController 中,我有以下方法:
public class ApiController : Controller
{
// GET: Api/ListarAgenda
public ActionResult ListarAgenda()
{
AgendaDAO adao = new AgendaDAO();
return Json(adao.Listar(), JsonRequestBehavior.AllowGet);
}
// GET: Api/ListarAgendamento
public ActionResult ListarAgendamento()
{
AgendamentoDAO adao = new AgendamentoDAO();
return Json(adao.Listar(), JsonRequestBehavior.AllowGet);
}
}
我的 Json 结果:
API/ListarAgenda
[
{
"AgendaID": 13,
"data": "/Date(1476327600000)/",
"agentamentos": [],
"status": null
},
{
"AgendaID": 14,
"data": "/Date(1476669600000)/",
"agentamentos": [],
"status": null
}
]
Api/ListarAgendamento
[
{
"AgendamentoID": 72,
"cliente": {
"ClientesID": 1007,
"Nome": "Maria Zilda",
"CPF": "00124794321",
"Telefone": 30198269,
"Estado": "PR",
"Cidade": "Curitiba",
"Rua": "Altevir De Souza Gonçalves",
"Numero": 59,
"Lat": "-25.3955309",
"Long": "-49.2168943"
},
"data": "/Date(1476327600000)/",
"botijao": "P13",
"quantidade": 1,
"veiculo": "VW Saveiro ",
"status": null
}]
我的问题是:我需要在来自 Api/ListarAgenda 的 json 结果中查看带有客户属性的议程列表。像这样的:
[
{
"AgendaID": 13,
"data": "/Date(1476327600000)/",
"agentamentos": [
{
"AgendamentoID": 72,
"cliente": {
"ClientesID": 1007,
"Nome": "Maria Zilda",
"CPF": "00124794321",
"Telefone": 30198269,
"Estado": "PR",
"Cidade": "Curitiba",
"Rua": "Altevir De Souza Gonçalves",
"Numero": 59,
"Lat": "-25.3955309",
"Long": "-49.2168943"
},
"data": "/Date(1476327600000)/",
"botijao": "P13",
"quantidade": 1,
"veiculo": "VW Saveiro ",
"status": null
}],
"status": null
}
]
“包含”效果不佳。我该怎么做?
【问题讨论】: