title: Using Dapper Dot Net get last inserted id
body: <p>I am using <strong>Microsoft Visual Studio Express 2012 for Web</strong> to develop the MVC5 application. I want to get last inserted ID by using Dapper dot net. I got solutions here but they are working on SQL Server 2012 (Management Studio) but when I run the query in code then returning value is wrong. Here are pieces of code that I have tried already to get last inserted ID</p>
  
  <pre><code>SqlConnection _db = new SqlConnection("String");
  
          string query_1 = @"DECLARE @InsertedRows AS TABLE (user_id int);Insert into users (stuff) OUTPUT Inserted.user_id INTO @InsertedRows values(@stuff); SELECT user_id FROM @InsertedRows";
          string query_2 = @"Insert into users (stuff) OUTPUT Inserted.user_id values(@stuff);";
          string query_3 = @"Insert into users (stuff) values(@stuff); SELECT SCOPE_IDENTITY()";
  
          1. var id = _db.Query&lt;int&gt;(query_x, new { stuff = @stuff });
          2. var id = _db.Execute(query_x, new { stuff = @stuff });
  </code></pre>
  
  <p>but the value of ID in both cases is 1 but not actual result. but when I run the same query on SQL management Studio then all things okay. Please help to fix this problem. </p>