c# – Converts an SQL query to a Query in Entity

Question:

I asked this question in another forum, but the content of the discussion followed another path so I decided to open this topic. Without getting away from the subject, how do I perform this SQL query:

select p.RA, p.Nome, p.Modulo, a.Descricao
from inscricao as i, participante as p, Atividade as a 
where i.ParticipanteId = p.ParticipanteId and 
   i.AtividadeId = a.AtividadeId order by p.Modulo

in a query using the Entity?

Answer:

Try to do as follows.

var query = (from i in dbContext.inscricao
                     join p in dbContext.participante on i.ParticipanteId equals p.ParticipanteId
                     join a in dbContext.Atividade on p.AtividadeId equals a.AtividadeId
                     where i.periodo == ViewModel.periodo && i.data == ViewModel.data.
                     select new {
                         RA = p.RA,
                         Nome = p.Nome,
                         Modulo = p.Modulo,
                         Descricao = a.Descricao
                     })
                     .OrderBy(x => x.Modulo);
Scroll to Top
AllEscort