[HierarchyRoot]
    class Person : EntityBase
    {
        public Person(Guid id) : base(id)
        {
        }

        /// <summary>
        /// Gets or sets Rank.
        /// </summary>
        [Field]
        public int Rank { get; set; }
    }

    [HierarchyRoot]
    class Position : EntityBase
    {
        public Position(Guid id) : base(id)
        {
        }

        /// <summary>
        /// Gets or sets Rank.
        /// </summary>
        [Field]
        public int Rank { get; set; }
    }

var per = new Person(Guid.NewGuid());
                per.Rank = 1;

                var pos = new Position(Guid.NewGuid());
                pos.Rank = 1;

                var rank = Query.All<Position>().Where(r => r.Rank == 1).Single().Rank; // Ok here
                var people = Query.All<Person>().Where(p => p.Rank == Query.All<Position>().Where(r => r.Rank == 1).Single().Rank); //Exception

Xtensive.Storage.Linq.TranslationException : Unable to translate 'Query.All().Where(p => (p.Rank == Query.All().Where(r => (r.Rank == 1)).Single().Rank))' expression. See inner exception for details. ----> System.InvalidOperationException : Sequence contains no elements. at Xtensive.Storage.Linq.Materialization.MaterializationHelper.ThrowEmptySequenceException() at Xtensive.Storage.Linq.Materialization.ExpressionMaterializer.VisitMarker(MarkerExpression expression) at Xtensive.Storage.Linq.Expressions.Visitors.ExtendedExpressionVisitor.VisitUnknown(Expression expression) at Xtensive.Core.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Core.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b) at Xtensive.Core.Linq.ExpressionVisitor1.Visit(Expression e) at Xtensive.Storage.Linq.Materialization.ExpressionMaterializer.MakeLambda(Expression expression, TranslatorContext context) at Xtensive.Storage.Linq.Expressions.ItemProjectorExpression.ToLambda(TranslatorContext context) at Xtensive.Storage.Linq.Translator.VisitWhere(Expression expression, LambdaExpression le) at Xtensive.Storage.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind) at Xtensive.Core.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc) at Xtensive.Storage.Linq.Translator.VisitMethodCall(MethodCallExpression mc) at Xtensive.Core.Linq.ExpressionVisitor`1.Visit(Expression e) at Xtensive.Storage.Linq.Translator.Visit(Expression e) at Xtensive.Storage.Linq.Translator.TranslateTResult at Xtensive.Storage.Linq.QueryProvider.TranslateTResult

What am I doing wrong? (Except not using joins;))

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Mar 24 '10 at 13:13

xumix's gravatar image

xumix
425757682


One Answer:

AFAIK, this exception is thrown when .Single() call must really throw an exception on similar LINQ-to-Objects query.

I.e. Query.All<position>().Where(r => (r.Rank == 1)) contains either no elements, or more then one element. Likely, you must use either .SingleOrdDefault or .FirstOrDefault there (or change the condition).

TODO for us: fix top-level "TranslationException" here.

answered Mar 24 '10 at 15:28

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

var rank = Query.All<position>().Where(r => r.Rank == 1).Single().Rank; // Ok here

(Mar 24 '10 at 15:28) xumix xumix's gravatar image

Sorry, I missed this. We'll study the issue shortly.

(Mar 24 '10 at 15:28) Alex Yakunin Alex%20Yakunin's gravatar image

The issue was fixed yesterday.

Today we're going to run few more tests there to be fully sure there are no any related issues; after this we'll publish an update.

(Mar 24 '10 at 15:28) Alex Yakunin Alex%20Yakunin's gravatar image

Cool, thanks

(Mar 24 '10 at 15:28) xumix xumix'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

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Mar 24 '10 at 13:13

Seen: 2,667 times

Last updated: Mar 24 '10 at 13:13

powered by OSQA