question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Linq2db doesn't support read numeric into BigInteger

See original GitHub issue

Describe your issue

While reading entity with BigInteger property (dbtype - numeric(78,0)) - linq2db throws exception

Exception message: System.OverflowException: Numeric value does not fit in a System.Decimal
Stack trace: System.OverflowException: Numeric value does not fit in a System.Decimal
   at Npgsql.Internal.TypeHandlers.NumericHandlers.NumericHandler.Read(NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription)
   at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
   at Npgsql.NpgsqlDataReader.GetDecimal(Int32 ordinal)
   at lambda_method56(Closure, IQueryRunner, DbDataReader)
   at LinqToDB.Linq.QueryRunner.Mapper`1.Map(IDataContext context, IQueryRunner queryRunner, DbDataReader dataReader, ReaderMapperInfo& mapperInfo)
   at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
   at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
   at LinqToDB.Linq.Builder.FirstSingleBuilder.FirstSingleContext.<>c__DisplayClass4_0`1.<<GetFirstOrDefaultElement>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at LinqToDB.Linq.ExpressionQuery`1.LinqToDB.Async.IQueryProviderAsync.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Domain.Services.FundsTransferService.TransferAsync(String senderAddress, String recipientAddress, BigInteger amount) in 

Steps to reproduce

var transfer = await connection.Transfers.FirstOrDefaultAsync();

builder.Entity<Transfer>()
            .HasPrimaryKey(x => x.Id)
            .Property(x => x.Amount).HasPrecision(78).HasScale(0);

Environment details

Linq To DB version: 5.0.0

Database (with version): Postgres

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Mar 2, 2023

My bad, should be:

SetProviderField<DbDataReader, BigInteger, decimal>((DbDataReader rd, int idx) => rd.GetFieldValue<BigInteger>(idx));
0reactions
twilightruscommented, Mar 2, 2023

My bad, should be:

SetProviderField<DbDataReader, BigInteger, decimal>((DbDataReader rd, int idx) => rd.GetFieldValue<BigInteger>(idx));

Solved, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

LINQ throwing invalid cast exception on a bigint
The exception seems to be thrown from the Entity Framework. You might have the column set as int instead of bigint in the...
Read more >
[sqlite] "BIGINT" doesn't act like INTEGER on table creation ...
It is merely an integer column, completely separate from the rowid, whcih you happen to want to be the primary key. Since the...
Read more >
Supported Types and their Mappings
The following lists the built-in mappings when reading and writing CLR types ... numeric, decimal, byte, short, int, long, float, double, BigInteger (6.0+)....
Read more >
Announcing Entity Framework 7 Preview 5 - .NET Blog
Entity Framework 7 (EF7) Preview 5 has shipped with support for Table-per-Concrete type (TPC) mapping. This blog post will focus on TPC.
Read more >
W3layouts cms exploit
Which of the following raises the number 6 to the third power? ... Android Studio does not open missing essentian plugin android studio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found