How to perform a Left Join with LINQ C # using my SQL?

-1

Example that works in SQL:

select * from Doacoes
inner join Projetos on Projetos.IdProjeto = Doacoes.IdProjeto
left join Pedidos on Doacoes.IdDoacao = Pedidos.IdDoacao
left join Recompensas on Pedidos.IdRecompensa = Recompensas.IdRecompensa
where Doacoes.IdUsuario = 2017

I did the rewrite this way, but it does not work:

from d in banco.Doacoes
join p in banco.Projetos on d.IdProjeto equals p.IdProjeto
join pedi in banco.Pedidos on d.IdDoacao equals pedi.IdDoacao into pedi
join recompensa in banco.Recompensas  on recompensa.IdRecompensa equals 
pedi.IdRecompensa into pedi
    
asked by anonymous 07.12.2017 / 12:39

1 answer

0

In order to have left join Entity Framework you will have to do the following

from d in banco.Doacoes
join p in banco.Projetos on d.IdProjeto equals p.IdProjeto
join pedi in banco.Pedidos on d.IdDoacao equals pedi.IdDoacao into pediLeft
from pedi in pediLeft.DefaultIfEmpety()
join recompensa in banco.Recompensas on recompensa.IdRecompensa equals pedi.IdRecompensa into recoLeft
from recompensa in recoLeft.DefaultIfEmpety()

Take a look at this Entity Framework Left Join question too.

    
07.12.2017 / 13:32