Error executing a query with npgsql + dapper in postgresql

1

I can get my "user" object that has a "Login and Password" inside it, and when I run the function through my ORM, I get the following error message:

  

{"42883: operator does not exist: @ character varying"}.

Could anyone tell me what might be causing such an error? Here 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();
  }
    
asked by anonymous 30.08.2017 / 07:53

1 answer

1

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

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();
}
    
30.08.2017 / 13:18