-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复 Dapper.Contrib.Extensions 中 Insert 方法,此方法返回值为long类型,但内部各类型数据库获取自增ID,都是转换为int32,当ID超过超过Int32(2147483647)时,出现bug。 #4
Comments
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: 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 : Dapper.Contrib/src/Dapper.Contrib/SqlMapperExtensions.cs Lines 380 to 385 in cf24f6b
|
@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: |
修复 Dapper.Contrib.Extensions 中 Insert 方法,此方法返回值为long类型,但内部各类型数据库获取自增ID,都是转换为int32,当ID超过超过Int32(2147483647)时,出现bug。
主要涉及到的内容为接口 ISqlAdapter 中的方法:
`
///
/// The interface for all Dapper.Contrib database operations
/// Implementing this is each provider's model.
///
public partial interface ISqlAdapter
{
///
/// Inserts into the database, returning the Id of the row created.
///
/// The connection to use.
/// The transaction to use.
/// The command timeout to use.
/// The table to insert into.
/// The columns to set with this insert.
/// The parameters to set for this insert.
/// The key columns in this table.
/// The entity to insert.
/// The Id of the row created.
int Insert(IDbConnection connection, IDbTransaction transaction, int? commandTimeout, string tableName, string columnList, string parameterList, IEnumerable keyProperties, object entityToInsert);
....
`
,此方法返回值改为long可修复此问题。
The text was updated successfully, but these errors were encountered: