2

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!

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are right. I use select new {dc, dc.Archivo} to obtain the table Archivo.
0

have you tried using the Include() statement? I think it would look something like this

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

Comments

0

how about:

var detallesContenido =
  from contenido in guiaContext.Contenido
      where contenido.PuntoInteres.id_punto == puntoInteresID && contenido.DetalleContenido.Any(c=>c.Idioma.ds_idioma == idiomaCliente)
  select contenido.DetalleContenido;

1 Comment

I want to retrieve DetalleContenido AND Archivo.
0

My solution:

var detallesContenido =
   from contenido in guiaContext.Contenido
      where contenido.PuntoInteres.id_punto == puntoInteresID
   from detalleContenido in contenido.DetalleContenido
      where detalleContenido.Idioma.ds_idioma == idiomaCliente
   select new { detalleContenido, detalleContenido.Archivo };

Thank you!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.