I'm working with C # ASP.NET MVC5, I'm new to this technology, I'm doing a web page where I need to display data from three tables in the view, I show them the structure of the database.
log table
|-----------------|-------------------|------------|
| id_registro | 2 | 3 |
|-----------------|-------------------|------------|
| fecha_registro | 2017-05-21 | 2017-05-26 |
|-----------------|-------------------|------------|
| evento | Aumento del valor | Disminuye |
|-----------------|-------------------|------------|
| id_pais | 1 | 5
Table Country (n_pais)
| id_pais | 1 | 5 |
|-----------|---------|-------|
| pais | Austria | India |
|-----------|---------|-------|
| id_region | 4 | 3 |
Region table (n_region)
| id_region | 3 | 4 |
|-----------|------|---------|
| region | Mali | Venecia |
In the view what I want to show is:
Registro Fecha Evento Pais Region
2 2017-05-21 Aumento del valor Austria Venecia
3 2017-05-26 Disminuye India Mali
The code in the view
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.id_registro
</th>
<th>
@Html.DisplayNameFor(model => model.fecha_registro)
</th>
<th>
@Html.DisplayNameFor(model => model.evento)
</th>
<th>
@Html.DisplayNameFor(model => model.n_pais.pais)
</th>
<th>
@Html.DisplayNameFor(model => model.n_region.region)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.id_registro)
</td>
<td>
@Html.DisplayFor(modelItem => item.fecha_registro)
</td>
<td>
@Html.DisplayFor(modelItem => item.evento)
</td>
<td>
@Html.DisplayFor(modelItem => item.n_pais.pais)
</td>
<td>
@Html.DisplayFor(modelItem => item.n_region.region)
</td>
</tr>
}
</table>
The driver
The query in SQL
SELECT * FROM registro, n_pais, n_region
WHERE registro.id_pais = n_pais.id_pais AND
n_pais.id_region = n_region.id_region
LinQ
var query = from q in db.registro
join r in db.n_pais on q.id_pais equals r.id_pais
join m in db.n_region on r.id_region equals m.id_region
select q;
return View(query.ToList());
In the view you can see the results of the registration and country table, however, the region remains empty. What can I do, what did I do wrong?