title: How to combine 2 tables using Entity Framework 6 and Linq in an MVC Project?
body: <p>I want to know how to get data from relationals tables.</p>
  
  <p>I want to get the images from the table named "Noticias1" that is relationated with "Noticias" (Noticias is an spanish word that means News sorry but it is for my University).</p>
  
  <p>here the <strong>Diagram Image</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/VxpTQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VxpTQ.png" alt="enter image description here"></a></p>
  
  <p>Here my "<strong>Noticias1</strong>" table that gets the images that will contain the news in table "Noticias" </p>
  
  <p><a href="https://i.stack.imgur.com/fpz6H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fpz6H.png" alt="enter image description here"></a></p>
  
  <p>Here my "<strong>Noticia</strong>" Table that only contain 1 "Noticia" that means News in english <a href="https://i.stack.imgur.com/JepER.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JepER.png" alt="enter image description here"></a></p>
  
  <p>Here the <strong>actual view IMG</strong> 
  <a href="https://i.stack.imgur.com/IpRCh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IpRCh.png" alt="enter image description here"></a></p>
  
  <p>As you can see it only shows "Noticias" Table that only have 1 News that is not the problem.</p>
  
  <p>Now I want to get the all the Images from "Noticias1" to every News in
  the table "Noticias" to show it in my view. (the named 1_0 will be the
  featured img).</p>
  
  <p>Here my <strong>Controller</strong> </p>
  
  <pre><code>public class NoticiasController : Controller
      {
          // GET: Noticias
          public ActionResult Index(int? page)
          {
              var entities = new Model.CobecaIntranetEntities();
              //where n.FeHasta &lt; DateTime.Now &amp;&amp; n.Activo
  
  
              var noticias = from n in entities.Noticias
                             where n.Activo &amp;&amp; n.FeDesde &lt;= DateTime.Now &amp;&amp; DateTime.Now &lt;= n.FeHasta
                             select n;
              var noticiasArray = noticias.ToArray();
  
              int pageSize = 10;
              int pageNumber = (page ?? 1);
  
              return View(noticiasArray.ToPagedList(pageNumber, pageSize));
          }
      }
  </code></pre>
  
  <p>Here my View</p>
  
  <pre><code>@model PagedList.IPagedList&lt;IntranetCorporativa.Model.Noticias&gt;
  @using PagedList;
  @using PagedList.Mvc;
  @{
      var format = "dddd, MMMM dd, yyyy";
      ViewBag.Title = "Index";
      Layout = "~/Views/Shared/_LayoutPage.cshtml";
      string principalTitulo = Model[0].Titulo;
      string principalContenido = Model[0].Contenido;
      DateTime principalFechaDesde = Convert.ToDateTime(Model[0].FeDesde);
      DateTime principalFechaHasta = Convert.ToDateTime(Model[0].FeHasta);
  }
  
  &lt;script type="text/javascript"&gt;
      function changeDisplay(e) {
  
          var principalTitulo = $(e).text();
          var principalContenido = $(e).siblings(".vNoticiaContenido:first").html();
          var principalFecha = $(e).siblings(".vNoticiaFecha:first").val();
  
          $("#currentprincipalTitulo").html(principalTitulo);
          $("#currentprincipalContenido").html(principalContenido);
          $("#currentprincipalFecha").html(principalFecha);
      }
  &lt;/script&gt;
  
  &lt;style&gt;
      .uppercase {
          text-transform: uppercase;
      }
  
      .limit {
          text-overflow: ellipsis;
          word-wrap: break-word;
          overflow: hidden;
          max-height: 3em;
          line-height: 1.7em;
      }
  &lt;/style&gt;
  &lt;!-- CONTENIDO --&gt;
  &lt;div class="col-md-12 main"&gt;
  
      &lt;div class="header sec-title-hd"&gt;
          &lt;div class="bg-calendar"&gt;&lt;/div&gt;
          &lt;div class="col-md-7"&gt;
              &lt;h5 class="pull-left"&gt;NOTICIAS&lt;/h5&gt;
              &lt;div&gt;
                  &lt;a href="dashboard.html" class="btn sky-blue n-radius-b"&gt; &lt;img src="slider/img/arrow-left.png"&gt; VOLVER&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="content-inter"&gt;
          &lt;div class="container-fluid sec-title-hd-sub"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-7"&gt;
                      &lt;div&gt;
                          &lt;figure class="img_N"&gt;
                              &lt;img id="currentprincipalImagen" src="#" class="img-responsive" alt="Here Principal IMG" /&gt;
                              &lt;figcaption&gt;
                                  &lt;p id="currentprincipalImagenTitulo"&gt;Here Img Description&lt;/p&gt;
                              &lt;/figcaption&gt;
                          &lt;/figure&gt;
                      &lt;/div&gt;
                      &lt;div class="textnota"&gt;
                          &lt;br&gt;
                          &lt;h5 id="currentprincipalTitulo" class="titulo_N uppercase"&gt;@principalTitulo&lt;/h5&gt;
                          &lt;p class="time"&gt;FeDesde: @principalFechaDesde.ToString(format)&lt;/p&gt;
                          &lt;p class="time"&gt;FeHasta: @principalFechaHasta.ToString(format)&lt;/p&gt;
                          &lt;p class="time"&gt;Hoy: @DateTime.Now.ToString(format)&lt;/p&gt;
                          &lt;div class="noti_P"&gt;
                              &lt;p id="currentprincipalContenido"&gt;@principalContenido&lt;/p&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-5"&gt;
                      &lt;!-- Lado Derecho --&gt;
                      @foreach (IntranetCorporativa.Model.Noticias n in Model)
                      {
                          &lt;blockquote class="blockquote-nopadding bg-calendar-border-left"&gt;
                              &lt;p class="time_f principalTitulo"&gt;@n.FeDesde.ToString(format)&lt;/p&gt;
                              &lt;a href="#" onclick="changeDisplay(this)" class="titulo_N"&gt;@n.Titulo&lt;/a&gt;
                              &lt;p class="text-justify limit vNoticiaContenido"&gt;@n.Contenido&lt;/p&gt;
                          &lt;/blockquote&gt;
                      }
                      Págnia @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) de @Model.PageCount
                      @Html.PagedListPager(Model, page =&gt; Url.Action("Index", new { page }))
                      &lt;div&gt;
  
                      &lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Thanks for everyhing.</p>