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 at 07:22

Gushchin%20Anton's gravatar image

Gushchin Anton
11131925

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