How do I perform an insert to database and return inserted identity with Dapper?
I\'ve tried something like this:
string sql = \"DECLARE @ID int; \"
Not sure if it was because I'm working against SQL 2000 or not but I had to do this to get it to work.
string sql = "DECLARE @ID int; " +
"INSERT INTO [MyTable] ([Stuff]) VALUES (@Stuff); " +
"SET @ID = SCOPE_IDENTITY(); " +
"SELECT @ID";
var id = connection.Query(sql, new { Stuff = mystuff}).Single();