Creating joins in the Entity Framework with tables without mapping

I need help: I ​​need to make a connection to 3 tables, but one of them was not displayed by the Entity Framework, because it is just a relational table, I need something like this:

select * 
from Promocao p
join ProdutoPromocao as pp on pp.PromocaoId = p.IdPromocao
join Produto as pr on pp.ProdutoId = pr.IdProduto
join Boteco as b on pr.botecoId = b.IdBoteco
where b.IdBoteco = 1

but the table was ProdutoPromocaonot displayed, how can I do this using the Entity Framework?

I thought of something like:

(from pr in db.Promocao
 join p in db.Produto on (pr.Produto.Select(x=>x.IdProduto)) equals p.IdProduto //this line is not working, I would need something like pr.Produto.IdProduto but it does not offer me this alternative
 join b in db.Boteco on p.BotecoId equals b.IdBoteco
 where b.IdBoteco == idBoteco
 select pr
 ).ToList();

Someone please help me.

+4
source share
2 answers

You can try as shown below.

(from pr in db.Promocao
 join p in db.Produto on (pr.Produto.Select(x=>x.IdProduto).FirstOrDefault()) equals p.IdProduto 
 join b in db.Boteco on p.BotecoId equals b.IdBoteco
 where b.IdBoteco == idBoteco
 select pr
 ).ToList();
+1
source

EF ( , ) . , , , (, ), EF .

:

from pr in db.Promocao
from p in pr.Produto
let b = p.Boteco
... (the rest)
+1

Source: https://habr.com/ru/post/1653245/


All Articles