0

I'm trying to add a parameter to this sql query to be executed against an Entity Framework context. I'm having trouble figuring out the syntax. Here is what I have so far:

db.Participantes.SqlQuery("SELECT participanteID, nome, email, telefone, unidadeCE, voucherNumero, dataCadastro," +
                          "(SELECT TOP(1) tipo FROM ParticipanteResultado pr WHERE p.participanteID = pr.participanteID ORDER BY quantidadeValidas DESC) AS tipo" +
                          "FROM Participante p WHERE p.unidadeCE = @param", new { param = unidade }).ToList()
2
  • Can you elaborate on how your code "doesn't work"? What were you expecting, and what actually happened? If you got an exception, post the line it occurred on and the exception details. Commented Dec 11, 2014 at 17:51
  • What i meant is i don't know how to add the parameter, i know it must be a object but i never used this kind before Commented Dec 11, 2014 at 18:00

1 Answer 1

3

Here is what you are looking for as for as adding parameters to your EF query.

db.SqlQuery<TEntity>("SELECT * FROM Table WHERE Column = @ParamName", 
               new SqlParameter("ParamName", parameterValue)).ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks buddy, that's exactly what i was looking for ! Just don't know why the down votes :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.