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?
-
You still did not fix as Habib suggested. That's the line that causes error.Mehrzad Chehraz– Mehrzad Chehraz2015年05月12日 14:23:07 +00:00Commented May 12, 2015 at 14:23
2 Answers 2
Instead of
queue = queue.OrderBy(f => orderByLambda);
Use:
queue = queue.OrderBy(orderByLambda);
answered May 12, 2015 at 13:57
Habib
224k30 gold badges420 silver badges446 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Two notes on your code:
- 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. - 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
nullCheckExpressionandparameterExpressionare. In general, this is not how you would sort LINQ to Entities anyway - it should be something likequeue.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)
answered May 12, 2015 at 14:30
GalacticCowboy
11.8k2 gold badges46 silver badges69 bronze badges
Comments
lang-cs