Simple model:

[Serializable]
[HierarchyRoot]
public class MyEntity : Entity
{
    [Field, Key]
    public int Id { get; private set; }

    [Field(Length = 100)]
    public string T1 { get; set; }

    [Field(Length = 100)]
    public string T2 { get; set; }
}

and simple query:

session.Query.All<MyEntity>()
    .GroupBy(a => new { a.T1, a.T2 }, (a, b) => new { a.T1, a.T2, Count = b.Count() })
    .ToArray();

works ok, but if I replace anonymous types with Named:

session.Query.All<MyEntity>()
    .GroupBy(a => new K { T1 = a.T1, T2 = a.T2 }, (a, b) => new S { T1 = a.T1, T2 = a.T2, Count = b.Count() })
    .ToArray();

...

public class K
{
    public string T1 { get; set; }
    public string T2 { get; set; }
}
public class S
{
    public string T1 { get; set; }
    public string T2 { get; set; }
    public int Count { get; set; }
}

I got exception:

Xtensive.Orm.QueryTranslationException was unhandled
  Message=Unable to translate 'Query.All().GroupBy(
  a => new Program.K() {
    T1 = a.T1,
    T2 = a.T2
  },
  (a, b) => new Program.S() {
    T1 = a.T1,
    T2 = a.T2,
    Count = b.Count()
  }
)' expression. See inner exception for details.
  Source=Xtensive.Orm
  StackTrace:
       at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\QueryProvider.cs:line 85
       at Xtensive.Orm.Linq.QueryProvider.Execute[TResult](Expression expression) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\QueryProvider.cs:line 69
       at Xtensive.Orm.Linq.Queryable`1.GetEnumerator() in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Queryable.cs:line 65
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at Project28.Program.Main(String[] args) in c:\users\klekovkin\documents\visual studio 2010\Projects\Project28\Project28\Program.cs:line 35
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  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) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\KeyExpression.cs:line 69
            at Xtensive.Orm.Linq.Expressions.EntityExpression.Remap(Int32[] map, Dictionary`2 processedExpressions) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\EntityExpression.cs:line 73
            at Xtensive.Orm.Linq.Expressions.FieldExpression.Remap(Int32[] map, Dictionary`2 processedExpressions) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\FieldExpression.cs:line 77
            at Xtensive.Orm.Linq.ConstructorExpression.<>c__DisplayClass1a.<Remap>b__15(IMappedExpression mapped) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\ConstructorExpression.cs:line 75
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitGenericExpression(T generic) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 52
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitUnknown(Expression e) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 35
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\Projects\dataobjects.net\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 128
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.Process(Expression target, Func`2 genericProcessor) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 25
            at Xtensive.Orm.Linq.ConstructorExpression.<>c__DisplayClass1a.<Remap>b__17(KeyValuePair`2 kvp) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\ConstructorExpression.cs:line 78
            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) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\ConstructorExpression.cs:line 78
            at Xtensive.Orm.Linq.Expressions.ItemProjectorExpression.<>c__DisplayClass4.<Remap>b__3(IMappedExpression mapped) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\ItemProjectorExpression.cs:line 58
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitGenericExpression(T generic) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 52
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.VisitUnknown(Expression e) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 35
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\Projects\dataobjects.net\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 128
            at Xtensive.Orm.Linq.Expressions.Visitors.GenericExpressionVisitor`1.Process(Expression target, Func`2 genericProcessor) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\Visitors\GenericExpressionVisitor.cs:line 28
            at Xtensive.Orm.Linq.Expressions.ItemProjectorExpression.Remap(RecordQuery dataSource, Int32[] columnMap) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Expressions\ItemProjectorExpression.cs:line 58
            at Xtensive.Orm.Linq.Translator.VisitGroupBy(Type returnType, Expression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Translator.Queryable.cs:line 751
            at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Translator.Queryable.cs:line 142
            at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) in c:\Projects\dataobjects.net\Xtensive.Core\Xtensive.Core\Linq\QueryableVisitor.cs:line 34
            at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Translator.Expressions.cs:line 401
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\Projects\dataobjects.net\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 106
            at Xtensive.Orm.Linq.Translator.Visit(Expression e) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Translator.Expressions.cs:line 84
            at Xtensive.Orm.Linq.Translator.Translate[TResult]() in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\Translator.Materialization.cs:line 33
            at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression) in c:\Projects\dataobjects.net\Xtensive.Orm\Xtensive.Orm\Orm\Linq\QueryProvider.cs:line 80
       InnerException:

asked Feb 08 '12 at 03:09

pil0t's gravatar image

pil0t
207575763


One Answer:

Hello pil0t,

Thanks for nicely formatted report. However, it seems that the issue is already fixed and is available in the recently published DataObjects.Net 4.4.2 RC 2.

answered Feb 10 '12 at 02:21

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

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