The code below generates the following error:
Parameter '@ID' must be defined.
Am I doing something wrong or is not it possible to use variables in the SQL query with MySQL which aren't Dapper parameters?
In this example, @Slug is a Dapper parameter, but @ID is not. I'm using MySQL so I don't need to DEFINE @ID - it get's defined in the first use.
var sql = @"SELECT @ID := id, slug, Title, Text FROM posts WHERE slug = @Slug; SELECT * FROM comments where postid = @ID;";
using (var connection = GetOpenConnection())
{
var posts = connection.QueryMultiple(sql, new { Slug = slug })
.Map<Post, Comment, int>
(
Post => Post.ID,
Comment => Comment.ID,
(post, comments) => { post.Comments = comments; }
);
return posts.FirstOrDefault();
}