DapperLib / DapperLib/Dapper.Contrib
Insert<T> problem with identity exceeding int max value
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
we started experiencing problems after our table identity reached the max int value (2,147,483,647).
After deep checking the SqlMapperExtensions code, I noticed that even if the method signature is to return a "long" type, the return variable is defined as "int"; what happens is that the record is correctly inserted but the library throws a System.OverflowException when returning the identity value due to the implicit cast from int to long.
SqlMapperExtensions code :
int returnVal;
var wasClosed = connection.State == ConnectionState.Closed;
[...]
return returnVal;
For the moment the temporary fix is to pass to the method a List containing just one entity, so that the return value is the number of inserted rows, but this is working because we don't need the identity back after this insert operation.
By the way our Entity class has the id field of type "long" and tagged as "key", and the problem disappear if we force the identity on DB to a value lower than the max int, and of course it's reproduced by forcing back to a higher value.
Thanks for your attention, cheers!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in SqlMapperExtensions at the insertion path where returnVal is declared as int despite the method returning long. Reproduce with an identity above 2,147,483,647 and verify that insertion completes without System.OverflowException and returns the identity as a long.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100