Hi. Model:

/// <summary>
/// Some place
/// </summary>
[HierarchyRoot]
[Serializable]
public class Place : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    /// <summary>
    /// Наименование
    /// </summary>
    [Field]
    public string Name { get; set; }
}

/// <summary>
/// Company
/// </summary>
[HierarchyRoot]
[Serializable]
public class Company : Entity
{
    [Field, Key]
    public int Id { get; private set; }

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

    /// <summary>
    /// Owner
    /// </summary>
    [Field(Nullable = false)]
    public Man CompanyOwner { get; set; }

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

    /// <summary>
    /// Employees
    /// </summary>
    [Field]
    [Association(PairTo = "Owner")]
    public EntitySet<Employee> Employees { get; set; }
}

/// <summary>
/// Man
/// </summary>
[HierarchyRoot]
[Serializable]
public class Man : Entity
{
    [Field, Key]
    public int Id { get; private set; }

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

/// <summary>
/// Employee
/// </summary>
[Serializable]
public class Employee : Man
{
    /// <summary>
    /// Company
    /// </summary>
    [Field]
    public Company Owner { get; set; }
}

Init data:

var somePlace = new Place() { Name = "SomePlace" };

var leader1 = new Man() { Name = "Company leader 1" };

var company1 = new Company() { Name = "Company 1", CompanyOwner = leader1, Place = somePlace };

var emp = new Employee() { Name = "Slave 1", Owner = company1 };
var emp1 = new Employee() { Name = "Slave 2", Owner = company1 };
var emp2 = new Employee() { Name = "Slave 3", Owner = company1 };

Test:

[TestMethod]
public void TestOrder()
{
     var company = this.session.Query.All<Company>().Single(c => c.Name == "Company 1");

     var employees = company.Employees;

     var ordered = employees.OrderBy(e => e.Owner.Name).ThenBy(e => e.Owner.Place.Name).ThenBy(e => e.Name).ToList();
}

Exception:

Test method Project1.TestEntities.TestOrder threw exception: 
Xtensive.Orm.QueryTranslationException: Unable to translate 'Query.All().Where(p => (p.Owner.Key == $<@<Owner>>({ Owner = Company, (8) }).Owner.Key)).OrderBy(e => e.Owner.Name).ThenBy(e => e.Owner.Place.Name).ThenBy(e => e.Name)' expression. See inner exception for details. ---> System.InvalidCastException: Unable to cast object of type 'Xtensive.Orm.Rse.Providers.JoinProvider' to type 'Xtensive.Orm.Rse.Providers.SortProvider'.
    at Xtensive.Orm.Linq.Translator.VisitThenBy(Expression expression, LambdaExpression le, Direction direction)
   at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind)
   at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc)
   at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc)
   at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.VisitSequence(Expression sequenceExpression, Expression expressionPart)
   at Xtensive.Orm.Linq.Translator.VisitThenBy(Expression expression, LambdaExpression le, Direction direction)
   at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind)
   at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc)
   at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc)
   at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.Translate()
   at Xtensive.Orm.Linq.QueryProvider.Translate(Expression expression, CompilerConfiguration compilerConfiguration)
 --- End of inner exception stack trace ---
    at Xtensive.Orm.Linq.QueryProvider.Translate(Expression expression, CompilerConfiguration compilerConfiguration)
   at Xtensive.Orm.Linq.QueryProvider.Translate(Expression expression)
   at Xtensive.Orm.Linq.QueryProvider.Execute(Expression expression)
   at Xtensive.Orm.Linq.Queryable`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList(IEnumerable`1 source)
   at Project1.TestEntities.TestOrder() in TestEntities.cs: line 147

DO 4.6.3

asked Apr 01 '13 at 01:42

Anton%20Guschin's gravatar image

Anton Guschin
73223035

Hello Anton. The issue is confirmed.

(Apr 01 '13 at 04:43) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

One Answer:

Hello Anton,

fix would be available in DO 4.5.8/4.6.4

answered Apr 29 '13 at 06:45

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

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