Error Running a query with npgsql + Dapper in postgresql

Asked

Viewed 167 times

1

I can capture my "user" object that has inside of itself a "Login and a Password" and, when executing the function by my ORM, I catch the following error message:

{"42883: operator does not exist: @Character Varying"}.

Would anyone know what could be causing such a mistake? Below is the function to execute the query..

  public Usuario Login(Usuario user)
  {
      return this._db.Query<Usuario>("SELECT nome, login, senha FROM usuario WHERE login = @Login and senha = @Senha", new { user }).FirstOrDefault();
  }
  • And the parameters, you’re passing where?

1 answer

1

Your query defines two parameters: @Login and @Senha. They need to be passed through an anonymous object in the method Query:

public Usuario Login(Usuario user)
{
    return this._db.Query<Usuario>("SELECT nome, login, senha FROM usuario WHERE login = @Login and senha = @Senha", new { Login = "login_do_usuario", Senha = "senha_do_usuario" }).FirstOrDefault();
}
  • 1

    actually if the "user" object contains these identical parameters Dapper turns to get the value of each parameter correctly.

Browser other questions tagged

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