DO 5.0.4

Xtensive.Orm.QueryTranslationException : Unable to translate 'Query.All().Where(z => z.Pcs1.Concat(z.Pcs2).Concat(z.Employee2.Pcs1).Concat(z.Employee2.Pcs2).Concat((z.Employee1 as Employee).Pcs1).Concat((z.Employee1 as Employee).Pcs2).Any())' expression. See inner exception for details.

----> System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
at Xtensive.Orm.Linq.QueryProvider.Translate(Expression expression, CompilerConfiguration compilerConfiguration)
at Xtensive.Orm.Linq.QueryProvider.Execute(Expression expression)
at Xtensive.Orm.Linq.Queryable`1.GetEnumerator()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray(IEnumerable`1 source)

Exception throws in third query

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

[TestFixture]
public class RunTests
{
    protected TransactionScope TransactionScope { get; private set; }

    protected Domain Domain { get; private set; }

    protected Session Session { get; private set; }

    [TestFixtureSetUp]
    public void FixtureSetup()
    {
        var configuration = new DomainConfiguration("sqlserver://sa:12345678@localhost/DOLinqTest")
        {
            UpgradeMode = DomainUpgradeMode.Recreate
        };

        configuration.Types.Register(typeof(RunTests).Assembly);
        Domain = Domain.Build(configuration);

        using (var s = Domain.OpenSession())
        {
            using (s.Activate())
            {
                using (var t = s.OpenTransaction())
                {
                    Company.Populate();
                    t.Complete();
                }
            }
        }
    }

    [SetUp]
    public void SetUp()
    {
        Session = Domain.OpenSession();
        this.TransactionScope = this.Session.OpenTransaction();
    }

    [TearDown]
    public void TearDown()
    {
        if (TransactionScope != null)
        {
            TransactionScope.Dispose();
            TransactionScope = null;
        }

        if (Session != null)
        {
            Session.Dispose();
            Session = null;
        }
    }

    [Test]
    public void TestConcatMultilinks()
    {
        var company = Session.Query.All<Company>().Where(z => z.Pcs1.Concat(z.Pcs2).Any()).ToArray();

        var company1 = Session.Query.All<Company>().Where(z => z.Pcs1.Concat(z.Pcs2).Concat(z.Employee2.Pcs1).Concat(z.Employee2.Pcs2).Any()).ToArray();

        // Exception
        var company2 = Session.Query.All<Company>().Where(z => z.Pcs1.Concat(z.Pcs2).Concat(z.Employee2.Pcs1).Concat(z.Employee2.Pcs2)
                                                .Concat((z.Employee1 as Employee).Pcs1)
                                                .Concat((z.Employee1 as Employee).Pcs2).Any()).ToArray(); 
    }
}

Model:

/// <summary> Компания </summary>
[HierarchyRoot]
public class Company : Entity
{
    public Company(string model)
        : base(model)
    {
    }

    public static Company ById(string model)
    {
        return Query.SingleOrDefault<Company>(model);
    }

    [Key]
    [Field(Length = 50)]
    public string Key { get; set; }

    /// <summary> PC1 </summary>
    [Field]
    public EntitySet<Pc> Pcs1 { get; private set; }

    /// <summary> PC2 </summary>
    [Field]
    public EntitySet<Pc> Pcs2 { get; private set; }

    /// <summary> Сотрудник </summary>
    [Field]
    public PersonBase Employee1 { get; set; }

    /// <summary> Сотрудник </summary>
    [Field]
    public Employee Employee2 { get; set; }

    public static void Populate()
    {
        var vasya = new PersonBase("vasya");
        var petya = new Employee("petya");
        var company = new Company("ms") { Employee1 = vasya, Employee2 = petya };

        var model = new Product("3333") { Maker = "A", Type = "PC" };
        var pc = new Pc(100) { Model = model, Speed = 500, Ram = 64, HD = 5.0m, Price = 600.0000m, CD = "12x" };

        company.Pcs1.Add(pc);
        company.Pcs2.Add(pc);

        petya.Pcs1.Add(pc);
        petya.Pcs2.Add(pc);
    }
}

[HierarchyRoot]
public class Pc : Entity
{
    public Pc(int code) : base(code){}
    [Field,Key]
    public int Code { get; private set; }

    [Field]
    public int Speed { get; set; }

    [Field]
    public int Ram { get; set; }

    [Field(Length = 50)]
    public string CD { get; set; }

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

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

/// <summary>
/// Персоны
/// </summary>
[HierarchyRoot]
public class PersonBase : Entity
{
    public PersonBase(string model)
        : base(model)
    {
    }

    [Key]
    [Field(Length = 50)]
    public string Key { get; set; }

    public static PersonBase ById(string model)
    {
        return Query.SingleOrDefault<PersonBase>(model);
    }
}

/// <summary>
/// Сотрудник
/// </summary>
public class Employee : PersonBase
{
    /// <summary> PC1 </summary>
    [Field]
    public EntitySet<Pc> Pcs1 { get; private set; }

    /// <summary> PC2 </summary>
    [Field]
    public EntitySet<Pc> Pcs2 { get; private set; }

    public Employee(string model) : base(model)
    {
    }
}

asked Apr 16 '15 at 03:49

abelkin's gravatar image

abelkin
25337

edited Apr 17 '15 at 02:13


One Answer:

Hello, abelkin

Thank you for the report. We'll investigate it.

answered Apr 27 '15 at 03:35

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