0

I am trying to write a linq to SQL lambda query which is equivalent to the below SQL query.

Select t.Task_Id
FROM taskSet ts
JOIN taskSet tsg ON tsGroup.SetId = ts.SetId
JOIN tasks t ON t.task_id = tsg.TaskId AND t.task_type_id = 10 AND t.row_status = 1 AND t.status = 0
WHERE ts.TaskId = @TaskId

I have reached till the below. Now if I try to add one more join and do the check for && condition it gives me error. Please help me out on how to proceed with this.

m_context.TaskSet
  .Join( m_context.TaskSet, 
   ts => ts.SetId,
   tsg => tsg.SetId,
   (ts, tsg) => new {ts, tsg})
istepaniuk
  • 4,016
  • 2
  • 32
  • 60
San
  • 1,797
  • 7
  • 32
  • 56
  • What is the error you get? – ronen Jan 03 '13 at 07:15
  • i get - cannot apply operator && to operands of type 'int' and 'int' – San Jan 03 '13 at 07:29
  • Can you post your full code which cause the problem? – ronen Jan 03 '13 at 07:53
  • Visit Here: [http://stackoverflow.com/questions/9720225/how-to-perform-join-between-multiple-tables-in-linq-lambda] you may get some Idea..... One More Link: [http://stackoverflow.com/questions/5839896/simple-examples-of-joining-2-and-3-table-using-lamda-expression ] – RajeshKdev Jan 03 '13 at 10:34

1 Answers1

0

When equijoining (see the C# reference on Join) more than one collection, I would perhaps consider using the query syntax rather than the method chain, for clarity. The conditions you have set in the ON clause will have to go as .Where() conditions (and they will be moved to the WHERE clause on translation). For example:

from ts in m_context.TaskSets
join tsg in m_context.TaskSets on ts.SetId equals tsg.SetId 
join t in m_context.Tasks on tsg.TaskId equals t.task_id 
where (t.task_type_id == 10)
   && (t.row_status == 1)
   && (t.status == 0)
   && (ts.TaskId == taskId)
select new {ts, tsg};
istepaniuk
  • 4,016
  • 2
  • 32
  • 60