This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3345|Reply: 1

[Source] Resolved the Dapper.Contrib error "Value is too large or too small for Int32"

[Copy link]
Posted on 8/6/2023 2:04:48 PM | | | |
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)





Previous:Qv2ray connects the Trojan-Go service on Windows
Next:SQL Server finds the data that varchar converts to bigint error
 Landlord| Posted on 8/6/2023 2:14:21 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com