Converts an SQL query into Entity Query

Asked

Viewed 51 times

3

I asked this question in another forum, but the content of the discussion went another way so I decided to open this topic. Without running 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 Entity?

  • Put entities in question!

1 answer

1


Try to do it this way.

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);
  • Thank you Marconcilio, and now I’m picking up the syntax to include in this same query two more conditions: In the table of inscriptions I need to check if the field period == Viewmodel.periodo and date == Viewmodel.data.

  • changed the query

Browser other questions tagged

You are not signed in. Login or sign up in order to post.