DO 5.0.20

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

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

        using (var d = Domain.Build(dc))
        using (var s = d.OpenSession())
        using (s.Activate())
        using (s.OpenTransaction())
        {
            var link1 = new Link { Name = "a" };
            var link2 = new Link { Name = "b" };
            var link3 = new Link { Name = "c" };

            new TestEntity { Link = link1 };
            new TestEntity();
            new TestEntity { Link = link3 };

            var query = Query.All<TestEntity>().Select(it => it.Link ?? link2);

            Assert.Throws<QueryTranslationException>(() => query.Where(it => it.Name.Length > 0).ToArray()); // OK

            var ordered = query.OrderBy(it => it.Name).Select(it => it.Name).ToArray(); // QueryTranslationException expected, but, alas, not thrown

            Assert.False(ordered.SequenceEqual(new[] { "b", "a", "c" })); // Current - null link came first in ordered SQL result, "b" has been set on application side
            Assert.True(ordered.SequenceEqual(new[] { "a", "b", "c" })); // Just in case
        }
    }

    [HierarchyRoot]
    public class TestEntity : Entity
    {
        [Field] 
        [Key] 
        public int Id { get; private set; }

        [Field] 
        public Link Link { get; set; }
    }

    [HierarchyRoot]
    public class Link : Entity
    {
        [Field] 
        [Key] 
        public int Id { get; private set; }

        [Field] 
        public string Name { get; set; }
    }
}

asked Mar 05 '20 at 07:22

Gushchin%20Anton's gravatar image

Gushchin Anton
11272729


One Answer:

Hello Anton,

The bug is confirmed, I have created and issue for 5.0 as well as issue in our github repository here: https://github.com/DataObjects-NET/dataobjects-net/issues/48

answered Jul 14 '20 at 08:45

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

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