Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there some sort of syntax error with this LINQ JOIN?

I've looked at various questions on SO and other sites, and this appears to be the correct syntax to perform a JOIN in LINQ, however it's just not working:

var stages = (from stage in entityManager.TPM_TASKSTAGE select stage);
var results = (from task in pv.TPM_TASK
               join st in stages on st.STAGEID equals task.STAGEID
               where task.TASKTYPE == "Solution"
               select new SolutionTask());

Ignore, for now, the fact that I don't actually select anything of interest, but I'd like to have access to the st.NAME property on each row of TPM_TASK. The two tables are linked by STAGEID. I get the compiler error:

The name 'st' is not in scope on the left side of 'equals'. Consider swapping the expressions on either side of 'equals'.

In the LINQ join expression, both st and task have red squigglies. Please tell me I'm doing something dumb.

like image 646
Mike Christensen Avatar asked Apr 08 '13 21:04

Mike Christensen


1 Answers

Key selector from outer sequence should go first. Outer sequence in your case is pv.TPM_TASK. So, you should join on task.STAGEID equals st.STAGEID

var stages = (from stage in entityManager.TPM_TASKSTAGE select stage);
var results = (from task in pv.TPM_TASK
               join st in stages on task.STAGEID equals st.STAGEID // here
               where task.TASKTYPE == "Solution"
               select new SolutionTask());
like image 185
Sergey Berezovskiy Avatar answered Sep 28 '22 01:09

Sergey Berezovskiy