Different behaviour in 5.0.7-RC2 and 5.0.7

And maybe bug in both

See comments in example

using System;
using System.Linq;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;

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

        dc.Types.Register(typeof(Program).Assembly);

        using (var d = Domain.Build(dc))
        {
            // 5.0.7-RC2    Ok
            // 5.0.7        Ok
            ExecuteWithTestData(d,
                () =>
                {
                    Session.Current.Query.All<TestEntity>()
                        .Select(e => new Poco { Name = e.Name })
                        .OrderBy(e => e.Name)
                        .ToArray();
                });

            // 5.0.7-RC2    Ok
            // 5.0.7        Ok
            ExecuteWithTestData(d,
                () =>
                {
                    Session.Current.Query.All<TestEntity>()
                        .Select(e => new Poco { Name = e.Name, BaseName = e.Name })
                        .OrderBy(e => e.Name)
                        .ToArray();
                });

            // 5.0.7-RC2    Ok
            // 5.0.7        Fail
            ExecuteWithTestData(d,
                () =>
                {
                    Session.Current.Query.All<TestEntity>()
                        .Select(e => new Poco { Name = e.Name, BaseName = e.Name })
                        .OrderBy(e => e.BaseName)
                        .ToArray();
                });

            // 5.0.7-RC2    Fail
            // 5.0.7        Fail
            ExecuteWithTestData(d,
                () =>
                {
                    Session.Current.Query.All<TestEntity>()
                        .Select(e => new Poco { BaseName = e.Name })
                        .OrderBy(e => e.Name)
                        .ToArray();
                });

            // 5.0.7-RC2    Fail
            // 5.0.7        Fail
            ExecuteWithTestData(d,
                () =>
                {
                    Session.Current.Query.All<TestEntity>()
                        .Select(e => new Poco())
                        .OrderBy(e => e.Name)
                        .ToArray();
                });
        }
    }

    private static void ExecuteWithTestData(Domain domain, Action action)
    {
        CreateTestData(domain);

        ExecuteInNewSession(domain, action);

        ClearTestData(domain);
    }

    private static void ClearTestData(Domain domain)
    {
        ExecuteInNewSession(domain, () =>
        {
            Session.Current.Remove(Session.Current.Query.All<TestEntity>());
        });
    }

    private static void CreateTestData(Domain domain)
    {
        ExecuteInNewSession(domain, () =>
        {
            new TestEntity();
        });
    }

    private static void ExecuteInNewSession(Domain d, Action action)
    {
        using (var s = d.OpenSession())
        using (s.Activate())
        using (var t = s.OpenTransaction())
        {
            action.Invoke();
            t.Complete();
        }
    }
}

[Serializable]
internal class Poco : PocoBase
{
    public string Name { get; set; }
}

[Serializable]
internal class PocoBase
{
    public string BaseName { get; set; }
}

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

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

asked Jan 29 '16 at 03:17

Anton%20Guschin's gravatar image

Anton Guschin
73303035


One Answer:

Thank you, Anton.

I've already added your extra tests to the tests I had for POCO classes and their usage inside queries. Investigation will start a bit later.

Updated: Fixed in 5.0.8

answered Feb 02 '16 at 06:29

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

edited Feb 15 '16 at 01:03

Last two not working (DO 5.0.10)

.Select(e => new Poco { BaseName = e.Name }).OrderBy(e => e.Name)

.Select(e => new Poco()).OrderBy(e => e.Name)
(Oct 11 '16 at 06:35) Anton Guschin Anton%20Guschin's gravatar image
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