Il seguente codice genera il seguente errore:Variabili SQL non parametriche con connettore MySql/Net e Dapper?
Parameter '@ID' must be defined.
Sto facendo qualcosa di sbagliato o non è possibile utilizzare le variabili nella query SQL con MySQL, che non sono parametri Dapper?
In questo esempio, @Slug è un parametro Dapper, ma @ID no. Sto usando MySQL quindi non ho bisogno di DEFINE @ID - viene definito al primo utilizzo.
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();
}
Grazie, ho appena ricevuto lo stesso errore ore prima. –
Wow, mi ha davvero aiutato. Grazie molto! – harriyott
Grazie mille, blog molto utile !!! – Rida