The following example leads to Xtensive.Orm.QueryTranslationException

public class Program
{
    public 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.Types.Register(typeof(TestEntity2));

        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using (var d = Domain.Build(dc))
        {
            using (var s = d.OpenSession())
            using (s.Activate())
            using (s.OpenTransaction())
            {
                var test = new TestEntity2(s) { Str = "test" };
                new TestEntity(s) { TestEntity2 = test, Str = "test" };

                // This query is successfull
                var items1 = Query.All<TestEntity>()
                                 .Select(it => new
                                  {
                                      Test = it.TestEntity2 != null
                                                 ? string.Empty
                                                 : it.TestEntity2.Str
                                  })
                                 .Select(it => it.Test == null || it.Test.Length < 10
                                                   ? it.Test
                                                   : it.Test.Substring(0, 10))
                                 .ToList();

                // This query gets exception
                var items2 = Query.All<TestEntity>()
                                 .Select(it => new
                                  {
                                      Test = it.TestEntity2 != null
                                                 ? (string)null
                                                 : it.TestEntity2.Str
                                  })
                                 .Select(it => it.Test == null || it.Test.Length < 10
                                                   ? it.Test
                                                   : it.Test.Substring(0, 10))
                                 .ToList();
            }
        }  
    }

    [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 int Id { get; private set; }

        /// <summary>
        /// TestEntity2
        /// </summary>
        [Field]
        public TestEntity2 TestEntity2 { get; set; }

        /// <summary>
        /// Str
        /// </summary>
        [Field]
        public string Str { get; set; }
    }

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

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

        /// <summary>
        /// Str
        /// </summary>
        [Field]
        public string Str { get; set; }
    }
}

asked Oct 20 at 03:23

Vasily%20Smirnov's gravatar image

Vasily Smirnov
52

edited Oct 20 at 03:28


2 Answers:

Hello Vasily,

Thank you for the report. Yes, there is the error you've described.

Is it based on real query? I'm asking because these queries logically do not make any sense.

answered Oct 20 at 08:06

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

edited Oct 20 at 08:06

Hello, Alexey! Yes, this code doesn't make no sense, it's just to describe error :)

answered Nov 29 at 04:21

Vasily%20Smirnov's gravatar image

Vasily Smirnov
52

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