In my project I currently have 3 tables: Students, Occurrences and Users. In them I have views and controllers .
So far so good. My relationships are: Students & Occurrences (1, N) / Occurrences & Users (N, 1).
My problem is that in action Details, both Occurrences and Users, I can not show some relationship information. In the case of occurrences I can not show the name of the student and neither of the user (but in the Index, I can show these names), and in the users I can not show the name of the student (which would have to be shown by the fact of coming from the relationship of Students & Occorrences).
Here is my code that is in action that shows all the information, except those mentioned previously:
ActionResult Controller Occurrences
public ActionResult Detalhes(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Ocorrencia ocorrencia = db.Ocorrencias.Find(id);
if (ocorrencia == null)
{
return HttpNotFound();
}
return View(ocorrencia);
}
ActionResult Controller Users
public ActionResult Detalhes(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
//Usuario usuario = db.Usuarios.Find(id);
Usuario usuario = db.Usuarios.Include(o => o.Ocorrencias).AsNoTracking().FirstOrDefault(u => u.UsuarioID == id);
if (usuario == null)
{
return HttpNotFound();
}
return View(usuario);
}
Could anyone help me? Is this the case of a join?