Dapper.Contrib
Dapper.Contrib copied to clipboard
修复 Dapper.Contrib.Extensions 中 Insert 方法,此方法返回值为long类型,但内部各类型数据库获取自增ID,都是转换为int32,当ID超过超过Int32(2147483647)时,出现bug。
修复 Dapper.Contrib.Extensions 中 Insert 方法,此方法返回值为long类型,但内部各类型数据库获取自增ID,都是转换为int32,当ID超过超过Int32(2147483647)时,出现bug。
主要涉及到的内容为接口 ISqlAdapter 中的方法:
`
///
.... `
,此方法返回值改为long可修复此问题。
exactly, we want this update, especially when working with sqlite, it's id can be as big as int64.
this is an old issue for dapper.contrib, it's a breaking change so dapper.contrib won't merge the pr: https://github.com/DapperLib/Dapper/pull/1386
the work around is to insert a list with one item instead of single entity for this situation, the return value would be row count instead of primary key.
check the code of dapper contrib : https://github.com/DapperLib/Dapper.Contrib/blob/cf24f6bdc577b1e071c3764ddfb2cf3382531405/src/Dapper.Contrib/SqlMapperExtensions.cs#L380-L385
@wswind How we get the value of the new PK then? It's not just that the method returns the PK value, it also assigns it to the Id property on the provided object.
@mikesigs use dapper only, write the sql yourself. For sqlserver it's something like this: insert into ... output inserted.ID values ...
, then you can assign the id yourself. This is just a workaround.