Search code examples
c#entity-frameworkado.netlinq-to-entities

Ado.Net entity framework, linq: select multiples tables


I use these sentence in C# to retrieve data from tables DetalleContenido and Archivo:

var detallesContenido =
   from contenido in guiaContext.Contenido
      where contenido.PuntoInteres.id_punto == puntoInteresID
   from dc in contenido.DetalleContenido
      where dc.Idioma.ds_idioma == idiomaCliente
  select dc;

The relationship between tables is this:

DataBase Model

I use puntoInteresID and idiomaCliente to retrieve all rows from DetalleContenido and Archivo that are part of PuntoInteres but whith this sentence Archivo is allways null!!

The sql sentece equivalence is:

Select dc.ds_nomDetContenido, dc.ds_descDetContenido, ar.archivo
from Contenido c, DetalleContenido dc, Archivo ar, Idioma i
where c.id_punto = puntoInteresID
  and c.id_contenido = dc.id_contenido
  and dc.id_idioma = i.id_idioma
  and i.ds_idioma = idiomaCliente
  and dc.id_archivo = ar.id_archivo;

How can I retrieve Archivo too?

Thank you!


Solution

  • You can also do

    .Load()
    

    on the "reference" properity of the selected object (when you are using them).

    But as for your query, it seems your Archivo table is a 1 to many and you cannot "include" or "load" the "many" side of the equasion. You would have to do a "select dc.Archivo" I would think.