The following error is generated in the code below:
The '@ID' parameter must be specified.
Am I doing something wrong or cannot use variables in a SQL query with MySQL that are not Dapper parameters?
In this example, @Slug is a Dapper parameter, but @ID is not. I use MySQL, so I do not need DEFINE @ID - it is determined upon 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(); }
Mike gleason
source share