The code:

[HierarchyRoot]
public class A : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; set; }

    [Field]
    [Association(PairTo = "A")]
    public EntitySet<B> Bs { get; set; }
}

[HierarchyRoot]
public class B : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; set; }

    [Field(Nullable = false)]
    public A A { get; set; }
}

public class ADto
{
    public Guid Id { get; set; }

    public Guid[] Bs { get; set; }
}

public class BDto
{
    public Guid Id { get; set; }

    public Guid AId { get; set; }
}

var res = from a in Query.All<A>()
            select new ADto
                {
                    Id = a.Id,
                    Bs = a.Bs.ToArray().Select(b => b.Id).ToArray()
                };

res.ToArray();

The error looks like:

Xtensive.Orm.QueryTranslationException was unhandled
  Message=Unable to translate 'Query.All().Select(a => new ADto() {
  Id = a.Id,
  Bs = a.Bs.ToArray().Select(b => b.Id).ToArray()
})' 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 System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at ConsoleApplication1.Program.Main(String[] args) in C:\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 48
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       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.NotSupportedException
       Message=Unable to translate expression 'a.Bs.ToArray().Select(b => b.Id).ToArray()'. LINQ translator does not support method 'ToArray'.
       Source=Xtensive.Orm
       StackTrace:
            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.VisitMemberAssignment(MemberAssignment ma)
            at Xtensive.Linq.ExpressionVisitor.VisitBinding(MemberBinding binding)
            at Xtensive.Linq.ExpressionVisitor.VisitBindingList(ReadOnlyCollection`1 original)
            at Xtensive.Orm.Linq.Translator.VisitMemberInit(MemberInitExpression mi)
            at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
            at Xtensive.Orm.Linq.Translator.Visit(Expression e)
            at Xtensive.Orm.Linq.Translator.VisitLambda(LambdaExpression le)
            at Xtensive.Orm.Linq.Translator.BuildProjection(LambdaExpression le)
            at Xtensive.Orm.Linq.Translator.VisitSelect(Expression expression, LambdaExpression le)
            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:

And sometimes (for more complex scenarios) even like this:

2012-04-05 11:27:22 : Scheduler Error while Scheduler ExecuteTasks Xtensive.Orm.QueryTranslationException: Unable to translate 'Query.All().Where(t => t.Enabled).Select(t => new ScheduledTaskDto() {
  Id = t.Id,
  LastFinishedDate = t.LastFinishedDate,
  Schedule = new ScheduleDto() {
    Id = t.Schedule.Id,
    EndDate = t.Schedule.EndDate,
    Frequency = ((ScheduleFrequency)t.Schedule.Frequency),
    FromHour = t.Schedule.FromHour,
    Monthdays = t.Schedule.Monthdays.ToArray().Select(l => ((MonthDay)l.Linked.Order)).ToHashSet(),
    StartDate = t.Schedule.StartDate,
    ToHour = t.Schedule.ToHour,
    Type = ((ScheduleType)t.Schedule.Type),
    Weekdays = t.Schedule.Weekdays.ToArray().Select(l => ((WeekDay)l.Linked.Order)).ToHashSet()
  }
})' expression. See inner exception for details. ---> System.InvalidOperationException: Expression 't.Schedule.Monthdays.ToArray()' is not a sequence.
   at Xtensive.Orm.Linq.Translator.VisitSequence(Expression sequenceExpression, Expression expressionPart)
   at Xtensive.Orm.Linq.Translator.VisitSelect(Expression expression, LambdaExpression le)
   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.Linq.ExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 expressions)
   at Xtensive.Linq.ExpressionVisitor.VisitMethodCall(MethodCallExpression mc)
   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.VisitMemberAssignment(MemberAssignment ma)
   at Xtensive.Linq.ExpressionVisitor.VisitBinding(MemberBinding binding)
   at Xtensive.Linq.ExpressionVisitor.VisitBindingList(ReadOnlyCollection`1 original)
   at Xtensive.Orm.Linq.Translator.VisitMemberInit(MemberInitExpression mi)
   at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.VisitMemberAssignment(MemberAssignment ma)
   at Xtensive.Linq.ExpressionVisitor.VisitBinding(MemberBinding binding)
   at Xtensive.Linq.ExpressionVisitor.VisitBindingList(ReadOnlyCollection`1 original)
   at Xtensive.Orm.Linq.Translator.VisitMemberInit(MemberInitExpression mi)
   at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.Visit(Expression e)
   at Xtensive.Orm.Linq.Translator.VisitLambda(LambdaExpression le)
   at Xtensive.Orm.Linq.Translator.BuildProjection(LambdaExpression le)
   at Xtensive.Orm.Linq.Translator.VisitSelect(Expression expression, LambdaExpression le)
   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)
   --- End of inner exception stack trace ---
   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 System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Werp.Controller.Common.Scheduler.GetCachedTasks() in C:\Projects\Platform.Stable\Werp.Controller.Common\Helpers\Scheduler.cs:line 168
   at Werp.Controller.Common.Scheduler.TasksToExecute() in C:\Projects\Platform.Stable\Werp.Controller.Common\Helpers\Scheduler.cs:line 120
   at Werp.Controller.Common.Scheduler.ExecuteTasks(Object sender, ElapsedEventArgs e) in C:\Projects\Platform.Stable\Werp.Controller.Common\Helpers\Scheduler.cs:line 87

asked Apr 05 '12 at 03:58

xumix's gravatar image

xumix
425707682

edited Apr 05 '12 at 04:01

Any news? Bump

(Sep 17 '12 at 03:34) xumix xumix's gravatar image

Just a note: did you notice that you are getting LINQ translator does not support method 'ToArray'?

(Feb 04 '13 at 15:15) charx charx's gravatar image

One Answer:

Hello xumix,

as the exception says ToArray() at the moment is not supported by our LINQ translator. You can suggest a feature on our user voice site.

answered Feb 05 '13 at 04:18

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