1

i have this query

var resultado = from c in conn.carrera
                            join u in conn.usuario on c.idusuario equals u.idusuario
                            join t in conn.texto on c.idtexto equals t.idtexto
                            where c.estatus == 1
                            select c;

how do i get something as it:

select c.*,u.*,t.eltexto from carrera c
join usuario u on c.idusuario =u.idusuario
join texto t on c.idtexto = t.idtexto
where c.estatus = 1

you could see in the query i am select c.*, u.* and t.col1, then how can i get it in EF? because my first query gets only carrera.* but i need more data.

thanks

0

2 Answers 2

4

You could easily return a new object consisting all the properties of the three joined tables:

var resultado = from c in conn.carrera
                            join u in conn.usuario on c.idusuario equals u.idusuario
                            join t in conn.texto on c.idtexto equals t.idtexto
                            where c.estatus == 1
                            select new
                            { 
                               c.prop_1, 
                               c.prop_n, 
                               u.prop_1, 
                               u.prop_n, 
                               t.prop_1, 
                               t.prop_n 
                            };
Sign up to request clarification or add additional context in comments.

2 Comments

thank you i am checking what about select new{c,u,t.col_i_want};
That also works, however its always a good practice to only select the columns you need
0
select c.*,u.*,t.eltexto from carrera c
join usuario u on c.idusuario =u.idusuario
join texto t on c.idtexto = t.idtexto
where c.estatus = 1

from c in Carrerra
join u in Usuario on c.idusuario equals u.idusuario
join t in Texto on c.idtexto equals t.idtexto
where c.estatus = 1
select new {
  newcolumn1 = c.column1,
  c.column2,
  usercolumn1 = u.column1,
  usercolumn2 = u.column2,
  textcolumn = t.column1
}

if you want access to the objects themselves, then you could do

select new {
  usario = u,
  carrera = c,
  texto = t
}

Carrera, Usario, and Texto refer to the Models in your Entity Framework container.

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.