title: Non-parameter SQL Variables with MySql Connector/Net and Dapper?
body: <p>The code below generates the following error:   </p>
  
  <blockquote>
    <p>Parameter '@ID' must be defined.</p>
  </blockquote>
  
  <p>Am I doing something wrong or is not it possible to use variables in the SQL query with MySQL which aren't Dapper parameters?  </p>
  
  <p>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.</p>
  
  <pre><code>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&lt;Post, Comment, int&gt;
          (
          Post =&gt; Post.ID,
          Comment =&gt; Comment.ID,
          (post, comments) =&gt; { post.Comments = comments; }
          );
      return posts.FirstOrDefault();
  }
  </code></pre>