I have a mysql statement that I am passing to the dapper query method and it is returning a null object. I have created a POCO class to hold the returned result. I tested the query directly through a sql editor and it returned a result. Here is the code:
public ViewEmail GetViewEmail(string xId, int headerId)
{
using (IDbConnection connection = new MySqlConnection(_connectionString))
{
string sql = "SELECT * FROM ViewEmail " +
"WHERE Header_id = @Header_id " +
"AND x_id= '@x_id'";
var viewEmail = connection
.Query<ViewEmail>(sql, new { Header_id = HeaderId, x_id = xId })
.SingleOrDefault();
return viewEmail;
}
}
When using Prepared Statements, no need to wrap the parameter with '
. Try this instead:
string sql = "SELECT * FROM ViewEmail " +
"WHERE Header_id = @Header_id " +
"AND x_id= @x_id";
See Documentation