Hello everyone.

I try to read from database decimal value, which has more than 18 digits in it's integer part and get this exception:

System.OverflowException : Conversion overflows.
 at System.Data.SqlTypes.SqlDecimal.ToDecimal()
 at   Xtensive.Sql.Drivers.SqlServer.v09.TypeMapper.ReadDecimal(DbDataReader reader, Int32 index)
 at Xtensive.Orm.Providers.DbDataReaderAccessor.Read(DbDataReader source)
 at Xtensive.Orm.Providers.Command.<AsReaderOf>d__0.MoveNext()
 at Xtensive.Orm.Providers.SqlSessionHandler.<Xtensive.Orm.Providers.IProviderExecutor.ExecuteTupleReader>d__2.MoveNext()
 at Xtensive.Orm.Providers.SqlProvider.<OnEnumerate>d__9.MoveNext()
 at Xtensive.Orm.Rse.Providers.ExecutableProvider.<GetEnumerator>d__0.MoveNext()
 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
 at System.Linq.Enumerable.ToList(IEnumerable`1 source)
 at Xtensive.Orm.Rse.RecordSet.<GetGreedyEnumerator>d__0.MoveNext()
 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
 at Xtensive.Core.EnumerableExtensions.<Batch>d__20`1.MoveNext()
 at Xtensive.Core.EnumerableExtensions.<ApplyBeforeAndAfter>d__28`1.MoveNext()
 at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
 at System.Linq.Enumerable.First(IEnumerable`1 source)
 at Xtensive.Core.DelegateBindExtensions.<>c__DisplayClassd`6.<Bind>b__c(T2 arg2, T3 arg3, T4 arg4, T5 arg5)
 at Xtensive.Orm.Linq.QueryProvider.Execute(Expression expression)
 at System.Linq.Queryable.First(IQueryable`1 source)

I expect that if I could write this value to database, I can read it. This is simple example how to reproduce this error

using System;
using System.Linq;

using NUnit.Framework;

using Xtensive.Orm;
using Xtensive.Orm.Configuration;

public class Test
    public static void TestMethod()
        var connectionString = "Data Source=.; Initial Catalog=TestDb; Integrated Security=True;";
        var connectionInfo = new ConnectionInfo("sqlserver", connectionString);
        var cfg = new DomainConfiguration(connectionInfo);
        cfg.UpgradeMode = DomainUpgradeMode.Recreate;
        var domain = Domain.Build(cfg);
        using (var s = domain.OpenSession())
            using (s.Activate())
                using (var tr = s.OpenTransaction())
                    var entity = new TestEntity(Guid.NewGuid()) { field = 111111111111111111.000000m };

                using (var tr = s.OpenTransaction())
                    var entity = Session.Current.Query.All<TestEntity>().First();

public class TestEntity : Entity
    public TestEntity(Guid id) : base(id)

    public Guid Id { get; private set; }

    [Field(Precision = 24, Scale = 6)]
    public decimal field { get; set; }

asked Mar 19 '13 at 03:17

Maxim%20Kornev's gravatar image

Maxim Kornev

Hello Maxim, this is known issue unfortunately. We have plans to fix it, however there is no estimate at the moment.

(Mar 21 '13 at 14:40) Denis Krjuchkov Denis%20Krjuchkov's gravatar image
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA