The following SQL query returns 1 when the given values are available, and 0 when not available, and it works fine in SQL Server Management Studio,
select
case
when exists (select * from [dbo].[user]
where userName = 'admin'
and password = 'admin')
then cast(1 as bit)
else cast(0 as bit)
end
The same query with dapper ORM is the following:
public int login(string userName, string password)
{
string sql = "select case when exists(select * from user where userName = @usernamepara and password = @passwordpara) then cast(1 as bit) else cast(0 as bit )end";
using(IDbConnection conn = dbConnection)
{
conn.Open();
var res = conn.Execute(sql,
param: new { usernamepara = userName,
passwordpara = password });
conn.Close();
return res;
}
}
But when this method is called, it returns -1 for matching and non matching records. What's wrong here ?