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.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With