DapperLib / DapperLib/Dapper.Contrib

Exception in Dapper.Contrib SqlMapperExtension during the Insert "Value was either too large or too small for an Int32"

Open
#20 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Description

Scenario:
When explicitly inserting long value in primary key non identity column getting exception as "Value was either too large or too small for an Int32"

Method:
During the insert, the intermittent value stored in int and later i.e. before returning the value its being converted to long.

long Insert<T>(this IDbConnection connection, T entityToInsert, IDbTransaction transaction = null, int? commandTimeout = null) where T : class

Please find the highlighted information.

capture

Could somebody help me on this.

StackTrace:
at System.Decimal.ToInt32(Decimal d)
at System.Decimal.op_Explicit(Decimal value)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at SqlServerAdapter.Insert(IDbConnection connection, IDbTransaction transaction, Nullable1 commandTimeout, String tableName, String columnList, String parameterList, IEnumerable1 keyProperties, Object entityToInsert)
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable`1 commandTimeout)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Dapper.Contrib.Extensions.SqlMapperExtensions.Insert and the SqlServerAdapter.Insert entry points shown in the stack trace. Reproduce an insert using a long value in a non-identity primary key, then verify that the insert completes and returns the expected value without the Decimal.ToInt32 exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.