0

Can anyone help me? I am not able to convert the following expression in the SQL to equivalent Lambda expression,

ON nextT.TaskID = a.NextTaskID AND a.TaskID <> nextT.TaskID 

SQL to be converted

SELECT a.*
FROM            dbo.Action AS a INNER JOIN dbo.Task AS t 
ON t .TaskID = a.TaskID 
INNER JOIN dbo.Task AS nextT 
ON nextT.TaskID = a.NextTaskID AND a.TaskID <> nextT.TaskID //This need to converted

My incomplete attempt to convert expression is as follows

Equivalent Lambda Expression

    var context = new DataClassesDataContext();
    var data = (from a in context.Actions
                join t in context.Tasks on a.TaskID equals t.TaskID
                join nextT in context.Tasks 
on 
.......new {v1 = a.NextTaskID, v2 = a.TaskID} equals new {v1 = nextT.TaskID , v2 = nextT.TaskID}.....<---This is the problem.
                select new vw_NextTask1
                {
                    TaskID = a.TaskID,
                    Task = t.Title,
                    ActionID = a.ActionID,
                    Action = a.Title,
                    NextPhaseID = a.NextPhaseID,
                    NextTaskID = nextT.TaskID,
                    NextTask = nextT.Title,
                          Type = a.Type
                }).ToList<vw_NextTask1>();
    return data;
Shomaail
  • 493
  • 9
  • 30

1 Answers1

1

you can add a where clause.

var data = (from a in context.Actions
        join t in context.Tasks on a.TaskID equals t.TaskID
        join nextT in context.Tasks
        where nextT.TaskID != a.TaskID
m1o2
  • 1,549
  • 2
  • 17
  • 27
  • can we remove all the checks with ON and make all the checks in the where clause. Are these both ways equivalent? – Shomaail Mar 10 '16 at 10:52
  • 1
    There is a difference b/w condition in Where clause and On clause http://stackoverflow.com/questions/8311096/whats-the-difference-between-where-clause-and-on-clause-when-table-left-join – Shomaail Mar 10 '16 at 11:01