I'm trying to use a GroupBy with a custom generic class : this is failing with a translation error. Why is my query failing and what can I do to fix it?

Working query

var query = Query.All<MyEntity>().GroupBy(i => new { Key1 = i.Text, Key2 = i.Text2 });

Query failing with a translation error : Internal error: Unable to remap KeyExpression

var query = Query.All<MyEntity>().GroupBy(i => new  GroupKey<string,string> { Key1 = i.Text, Key2 = i.Text2 });

  public class GroupKey<T1, T2>
  {
    public T1 Key1 { get; set; }
    public T2 Key2 { get; set; }
  }

EDIT:

version 4.4.2.8034

Xtensive.Orm.QueryTranslationException occurred
  Message=Unable to translate 'Query.All().Where( => True).GroupBy( => new GroupKey<String>() {
  Key1 = .Supplier
})' expression. See inner exception for details.
  Source=Xtensive.Orm
  StackTrace:
       at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression)
       at Xtensive.Orm.Linq.QueryProvider.Execute[TResult](Expression expression)
       at Xtensive.Orm.Linq.Queryable`1.GetEnumerator()
       at Xtensive.Orm.Linq.Queryable`1.System.Collections.IEnumerable.GetEnumerator()
  InnerException: System.InvalidOperationException
       Message=Internal error: Unable to remap KeyExpression.
       Source=Xtensive.Orm
       StackTrace:
            at Xtensive.Orm.Linq.Expressions.KeyExpression.Remap(Int32[] map, Dictionary`2 processedExpressions)
            at Xtensive.Orm.Linq.Expressions.EntityExpression.Remap(Int32[] map, Dictionary`2 processedExpressions)
            at Xtensive.Orm.Linq.Expressions.FieldExpression.Remap(Int32[] map, Dictionary`2 processedExpressions)
            at Xtensive.Orm.Linq.ConstructorExpression.<>c__DisplayClass1a.<Remap>b__15(IMappedExpression mapped)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitGenericExpression(T generic)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitUnknown(Expression e)
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.Process(Expression target, Func`2 genericProcessor)
            at Xtensive.Orm.Linq.ConstructorExpression.<>c__DisplayClass1a.<Remap>b__17(KeyValuePair`2 kvp)
            at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
            at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
            at Xtensive.Orm.Linq.ConstructorExpression.Remap(Int32[] map, Dictionary`2 processedExpressions)
            at Xtensive.Orm.Linq.Expressions.ItemProjectorExpression.<>c__DisplayClass4.<Remap>b__3(IMappedExpression mapped)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitGenericExpression(T generic)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitUnknown(Expression e)
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.Process(Expression target, Func`2 genericProcessor)
            at Xtensive.Orm.Linq.Expressions.ItemProjectorExpression.Remap(RecordQuery dataSource, Int32[] columnMap)
            at Xtensive.Orm.Linq.Translator.VisitGroupBy(Type returnType, Expression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector)
            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[TResult]()
            at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression)
       InnerException:

asked Jan 19 '12 at 11:53

olorin's gravatar image

olorin
356838489

edited Jan 23 '12 at 09:30

Hello olorin,

Is there a chance to see the corresponding stack trace? You may send it by e-mail or just append to the question.

Thanks in advance.

(Jan 20 '12 at 04:14) Dmitri Maximov Dmitri%20Maximov's gravatar image

Dmitri : I added the complete exception.ToString()

(Jan 23 '12 at 09:31) olorin olorin's gravatar image

Thanks, will investigate the case

(Jan 23 '12 at 09:32) Dmitri Maximov Dmitri%20Maximov's gravatar image

The issue is reproduced

(Jan 24 '12 at 01:54) Denis Krjuchkov Denis%20Krjuchkov's gravatar image

One Answer:

The bug is fixed and will be included in the upcoming releases of v4.4.2 and v4.3.9

answered Jan 24 '12 at 05:50

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Thank you very much!

(Jan 24 '12 at 09:59) olorin olorin's gravatar image

Any idea when the next version for 4.4.2 will be released?

(Jan 31 '12 at 10:25) olorin olorin's gravatar image

It is expected to be released as RC this week.

(Jan 31 '12 at 10:48) Dmitri Maximov Dmitri%20Maximov'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