Hello DO 5.0.17

namespace Sample
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using NUnit.Framework;
    using Xtensive.Orm;
    using Xtensive.Orm.Configuration;

    internal class Program
    {
        private static void Main(string[] args)
        {
            var dc = new DomainConfiguration("sqlserver", "Data Source=.; Initial Catalog=DO40-Tests; Integrated Security=True;");

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

            dc.UpgradeMode = DomainUpgradeMode.Recreate;

            using (var d = Domain.Build(dc))
            {
                using (var s = d.OpenSession())
                using (s.Activate())
                using (var t = s.OpenTransaction())
                {
                    new TestEntity(s) { Dec = 9986664293295820m };

                    t.Complete();
                }

                using (var s = d.OpenSession())
                using (s.Activate())
                using (s.OpenTransaction())
                {
                    var count = Query.All<TestEntity>()
                        .Count(e => e.Dec != Math.Round(e.Dec, 2, MidpointRounding.AwayFromZero));

                    Assert.AreEqual(0, count);
                }
            }
        }

        [HierarchyRoot]
        public class TestEntity : Entity
        {
            /// <summary>Initializes a new instance of this class.</summary>
            /// <param name="session">The session.</param>
            public TestEntity(Session session) : base(session)
            {
            }

            [Key]
            [Field(Nullable = false)]
            public Guid Id { get; private set; }

            [Field]
            public decimal Dec { get; set; }
        }
    }
}

SQL query look like this ('float' make things a bit messy)

SELECT COUNT_BIG(*) AS [c01umn]
FROM [dbo].[Program.TestEntity] [a]
WHERE ([a].[Dec] <> (CAST((CASE
                               WHEN (([a].[Dec] * POWER(10, 2)) > 0) THEN ROUND((([a].[Dec] * POWER(10, 2)) + cast(0.5e0 AS float)), 0, 1)
                               ELSE ROUND((([a].[Dec] * POWER(10, 2)) - cast(0.5e0 AS float)), 0, 1)
                           END) AS decimal) / POWER(10, 2)));

asked Sep 20 at 03:29

Gushchin%20Anton's gravatar image

Gushchin Anton
971117


One Answer:

Hello Anton,

Thank you, I remember we had some issues with rounding of decimal and closed resolved it, probably we should reopen it and check it one more time

answered Sep 20 at 04:10

Alexey%20Kulakov's gravatar image

Alexey Kulakov
66215

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