DO 5.0.12

namespace Sample
{
    using System;
    using System.Linq;
    using Xtensive.Orm;
    using Xtensive.Orm.Configuration;
    using System.Transactions;
    using NUnit.Framework;

    class Program
    {
        static void Main(string[] args)
        {
            var sc = new SessionConfiguration("Default")
            {
                BatchSize = 25,
                DefaultIsolationLevel = IsolationLevel.ReadCommitted,
                CacheSize = 1000,
                DefaultCommandTimeout = 600,
                Options =
                    SessionOptions.Default
                    | SessionOptions.NonTransactionalReads
                    | SessionOptions.AutoActivation
                    | SessionOptions.SuppressRollbackExceptions
            };

            var dc = new DomainConfiguration("sqlserver", @"Data Source=.; Initial Catalog=DO40-Tests; Integrated Security=True;Connection Timeout=5;Application Name=Werp;")
            {
                UpgradeMode = DomainUpgradeMode.Recreate
            };

            dc.Sessions.Add(sc);
            dc.Types.Register(typeof(TestEntity));

            using (var domain = Domain.Build(dc))
            {
                using (var s = domain.OpenSession())
                using (s.Activate())
                using (var t = Session.Current.OpenTransaction())
                {
                    new TestEntity(1);
                    new TestEntity(2);

                    var query = Query.All<TestEntity>().Select(z => z.Int / 100.0m);

                    Assert.AreEqual(new [] { 0.01m, 0.02m }, query.ToArray());

                    //OK
                    Assert.AreEqual(0.03m, query.Sum(x => x));

                    query = Query.All<TestEntity>().Select(z => z.Int / 100m);

                    Assert.AreEqual(new [] { 0.01m, 0.02m }, query.ToArray());

                    //FAIL
                    Assert.AreEqual(0.03m, query.Sum(x => x));

                    t.Complete();
                }
            }
        }
    }

    [HierarchyRoot]
    [Serializable]
    class TestEntity : Entity
    {
        public TestEntity(int id) : base(id)
        {
        }

        [Field]
        [Key]
        public int Int { get; set; }
    }
}

Exception

System.InvalidCastException {"Specified cast is not valid."}

at System.Data.SqlClient.SqlBuffer.get_SqlDecimal()
at System.Data.SqlClient.SqlDataReader.GetSqlDecimal(Int32 i)
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__16`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.Sum[TSource](IQueryable`1 source, Expression`1 selector)
at Sample.Program.Main(String[] args) in D:\TestApp1\TestApp1\TestApp1\Program.cs:line 49
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

asked Apr 07 at 04:01

Gushchin%20Anton's gravatar image

Gushchin Anton
5122


One Answer:

Hello Anton

The issue is confirmed. I've created a task for it. The problem doesn't seem to be big so we'll fix it in the nearest releases.

answered Apr 11 at 05:08

Alexey%20Kulakov's gravatar image

Alexey Kulakov
45215

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