此问题已在此处针对 MSSQL 进行了介绍:
但此解决方案不适用于 mysql。
要LAST_INSERT_ID()
使用 mysql 将整数转换为整数,您必须这样做:
SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER);
堆栈跟踪是:
Dapper.<QueryInternal>d__13`1.MoveNext() in sqlMapper.cs:607
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +159
System.Linq.Enumerable.ToList(IEnumerable`1 source) +36
Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in sqlMapper.cs:535
有没有人在 MySQL 中解决了这个问题?
编辑:
我已经设法通过以下方式完成这项工作:
var id = connection.Query<ulong>("SELECT CAST(LAST_INSERT_ID() AS UNSIGNED INTEGER);").Single();
也许不理想,但它有效。