The following query
Connection.Query<User>("select * from User where Login=@login and Passwd=@passwd", new { login = _login, passwd=_passwd})
returns the following error
Must declare the scalar variable @login
The User model :
public class User
{
public int Id { get; set; }
public string Login { get; set; }
public string Passwd { get; set; }
}
UPDATE :
My problem was coming from the SQL connection
My connection string was
new OleDbConnection(@"Provider=sqloledb;Data Source=MYPC\SQLEXPRESS;Initial Catalog=MYDB;User Id=sa;Password=****;");
I've changed it to
new SqlConnection(@"Data Source=MYPC\SQLEXPRESS;Initial Catalog=MYDB;User Id=sa;Password=****;");
Tested with SQL Server, seems to be working fine:
[Test]
public void simple_select_test()
{
using (var conn = new SqlConnection(@"Data Source=.\sqlexpress; Integrated Security=true; Initial Catalog=test"))
{
var result = conn.Query<User>(
"select * from (select Id = 420, Login = 'foo', Passwd = 'bar') a where Login=@login and Passwd=@passwd",
new {login = "foo", passwd = "bar"}).First();
Assert.That(result.Login, Is.EqualTo("foo"));
Assert.That(result.Passwd, Is.EqualTo("bar"));
}
}