Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Created March 14, 2017 17:51
Show Gist options
  • Save wescleymatos/92da8694e3c53e6b8729f56f566984ce to your computer and use it in GitHub Desktop.
Save wescleymatos/92da8694e3c53e6b8729f56f566984ce to your computer and use it in GitHub Desktop.
public IQueryable<AlunoDto> BuscarTodosAlunoDtos()
{
var alunos = (
from al in _context.Alunos
join pe in _context.Pessoas on al.Id equals pe.Id
into alu
from alun in alu.DefaultIfEmpty()
join at in _context.AlunoTurmas on al.Id equals at.AlunoId into alt
from ats in alt.DefaultIfEmpty()
join tu in _context.Turmas on ats.TurmaId equals tu.Id into tur
from turm in tur.DefaultIfEmpty()
join se in _context.Series on turm.SerieId equals se.Id
into ser
from seri in ser.DefaultIfEmpty()
join cur in _context.Cursos on seri.CursoId equals cur.Id
into cu
from cur in cu.DefaultIfEmpty()
select new AlunoDto()
{
Id = al.Id,
DataNascimento = al.Pessoa.DataNascimento,
Matricula = al.Matricula,
Curso = cur,
Serie = seri,
Pessoa = alun,
Turma = turm
}
).GroupBy(c => c.Id, (key, c) => c.FirstOrDefault()).AsNoTracking();
return alunos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment