El código siguiente genera el error siguiente:Variables SQL sin parámetro con MySql Connector/Net y Dapper?
Parameter '@ID' must be defined.
¿Estoy haciendo algo mal o no es posible utilizar variables en la consulta SQL con MySQL que no son parámetros Dapper?
En este ejemplo, @Slug es un parámetro Dapper, pero @ID no lo es. Estoy usando MySQL, así que no necesito DEFINIR @ID, ya está definido en el primer uso.
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();
}
Gracias, acabo de recibir el mismo error horas antes. –
Guau, eso realmente me ayudó. ¡Muchas gracias! – harriyott
Muchas gracias, blog muy útil !!! – Rida