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
358●87●87●92
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.
Dmitri : I added the complete exception.ToString()
Thanks, will investigate the case
The issue is reproduced