Requirements: When using Dapper.Contrib to execute the Insert method, the return value of a single inserted data for the self-incrementing primary key field is the value after insertion, and when the return value is greater than 2147483647, Dapper.Contrib will throw the exception "The value is too large or too small for Int32".
When using Dapper.Contrib to insert data, the error "The value is too large or too small for Int32", and the database has been successfully inserted! suspected it was an issue with the ORM framework, then searched on GitHub and found it to be a known issue,The Dapper team has not fixed it because it is worried that it will be too impactful, and other authors have provided PR to Dapper, but it has also been closed, as shown in the figure below:
The hyperlink login is visible.
The reason for the exception is that after obtaining the self-value-added, taking the SQL Server adapter as an example, the cast is cast to an int type error, and the maximum value of int is (int. MaxValue): 2147483647, as shown in the figure below:
To reproduce the method, create a new table, add the primary key starting from 2147483648, and the SQL script is as follows:
Referencing the Dapper.Contrib package, perform the insert operation with the following code:
The error is as follows:
solution
Replace Dapper.Contrib with the Dapper.Contrib.Unofficial package with the following command:
The test no longer gives an error, as shown in the following figure:
Tip: Dapper.Contrib.Unofficial is not fully tested, please test it yourself before using it!
(End)
|