How to do a SELECT with Entity Framework?

2

I'm developing a kind of a QUIZ in C #, and I've already been able to do the INSERT questions and the answers in the database, but I'm having a hard time bringing the question and the bank's response to the quiz.

Type a select, because I just found select with entity in list form, and I need to make a select that it brings up the question and answers.

    
asked by anonymous 08.08.2016 / 22:26

1 answer

2

Are these questions in the same entity as the answers? If it is you must use an anonymous type:

var Resultado = Jogo.Select(x => new {x.Pergunta, x.RespostaUm, x.RespostaDois, x.RespostaTres, x.RespostaCerta});

If they are in separate tables, you have to do a JOIN with LINQ:

var Resultado = from Pergunta in Jogo
join Resposta in Respostas 
on Pergunta equals Respostas.Pergunta
select new { TextoPergunta = Jogo.Pergunta, TextResposta = Resposta.RespostaUm };

It's worth pointing out that all of LINQ is based on the SQL language, so it's not that difficult to understand the commands as long as you have basic SQL knowledge.

References: link

    
09.08.2016 / 15:07