2

I have the below Linq expression

var orderByLambda = Expression.Lambda<Func<Queue, int>>(
    nullCheckExpression, parameterExpression);

queue = context.Table
    .Join(context.tablea, cq => cq.a, r => r.a, (cq, r) => new { cq, r })
    .Join(context.tableb, s => s.r.b, se => se.b, (s, se) => new { s, se })
    .Join(context.tablec, u => u.s.cq.c, us => us.c, (u, us) => new { u, us })
    .Where(cq => cq.u.s.cq.c == Utilities.Authentication.c)
    .Where(cq => buildStatusOrder.Contains((BuildStatusEnum)cq.u.s.cq.d))
    .OrderBy(o => o.u.se.b)
    .Select(s => new QueueInfo
    {
        x = s.u.c,
        y = s.u.d,
        z = s.u.a
    });

queue = queue.OrderBy(f => orderByLambda);

var concat = queue.GroupBy(e => new { e.x, e.y, e.z })
    .OrderBy(v => v.FirstOrDefault().segmentID)
    .ToList()
    .Select(ss => new QueueInfo
    {
        x = ss.x,
        y = ss.y,
        z = ss.z,
    })
    .AsQueryable();

I am getting below error in concat

The LINQ expression node type 'Lambda' is not supported in LINQ to Entities.

What went wrong in my code?

1
  • You still did not fix as Habib suggested. That's the line that causes error. Commented May 12, 2015 at 14:23

2 Answers 2

3

Instead of

queue = queue.OrderBy(f => orderByLambda);

Use:

queue = queue.OrderBy(orderByLambda);
Sign up to request clarification or add additional context in comments.

Comments

0

Two notes on your code:

  1. LINQ to Entities (Entity Framework) wants to translate your query into SQL, so it can only do operations that it knows how to translate. For example, you can't use most common LINQ collection methods such as Contains, etc.
  2. You have defined a lambda object, but not what the actual expression does, to use for sorting - or at least, you haven't shown us what nullCheckExpression and parameterExpression are. In general, this is not how you would sort LINQ to Entities anyway - it should be something like queue.OrderBy(f => f.x).ThenBy(f => f.y); - you have to define which fields from your select are actually used for the sort. (See point number 1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.