DO 5.0.18

Example

using System;
using System.Linq;

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

using Domain = Xtensive.Orm.Domain;

class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");

        dc.Types.Register(typeof(Test));

        dc.UpgradeMode = DomainUpgradeMode.Recreate;
        var sessionConfiguration = new SessionConfiguration(SessionOptions.AutoActivation | SessionOptions.ServerProfile);

        using (var domain = Domain.Build(dc))
        {
            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                new Test { Dec = 10000000000000000000000000m };

                t.Complete();
            }

            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                Query.All<Test>()
                    .Select(e => e.Dec)
                    .Sum(); // OK

                Query.All<Test>()
                    .Select(e => e.Dec)
                    .Min(); // OK

                Query.All<Test>()
                    .Select(e => e.Dec)
                    .Max(); // OK

                Query.All<Test>()
                    .Select(e => e.Dec)
                    .Average(); // Fail
            }
        }
    }
}

[HierarchyRoot]
[Serializable]
public partial class Test : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field(Precision = 28, Scale = 2)]
    public decimal Dec { get; set; }
}

Exception

Unhandled Exception: System.Data.SqlTypes.SqlTypeException: Invalid numeric precision/scale.
   at System.Data.SqlTypes.SqlDecimal.CheckValidPrecScale(Int32 iPrec, Int32 iScale)
   at System.Data.SqlTypes.SqlDecimal.ConvertToPrecScale(SqlDecimal n, Int32 precision, Int32 scale)
   at Xtensive.Sql.Drivers.SqlServer.v09.TypeMapper.ReducePrecision(SqlDecimal d, Int32 newPrecision)
   at Xtensive.Sql.Drivers.SqlServer.v09.TypeMapper.ReadDecimal(DbDataReader reader, Int32 index)
   at Xtensive.Sql.TypeMapping.ReadValue(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[TSource](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__e`1.MoveNext()
   at Xtensive.Core.EnumerableExtensions.<ApplyBeforeAndAfter>d__16`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at lambda_method(Closure , Object[] , IEnumerable`1 , Session , Dictionary`2 , ParameterContext )
   at Xtensive.Core.DelegateBindExtensions.<>c__DisplayClassd`6.<Bind>b__c(T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at Xtensive.Orm.Linq.TranslatedQuery`1.Execute(Session session, ParameterContext parameterContext)
   at Xtensive.Orm.Linq.QueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Average(IQueryable`1 source)
   at Sample.Program.Main(String[] args) in C:\Projects\CleanDO\Sample\Program.cs:line 49

asked Feb 13 at 02:55

Gushchin%20Anton's gravatar image

Gushchin Anton
9111721


One Answer:

Hello Anton,

Try 5.0.19 Beta 2. We've made changes connected to decimal reading

answered Apr 24 at 03:55

Alexey%20Kulakov's gravatar image

Alexey Kulakov
71715

Your answer
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