Lambda 表达式等效于 SQL 的 from 子句中的“<>”与 Join

Lambda Expression equivalent of "<>" in from clause of SQL with Join

谁能帮帮我?我无法将 SQL 中的以下表达式转换为等效的 Lambda 表达式

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

SQL待转换

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

我不完整的转换表达式的尝试如下

等价的 Lambda 表达式

    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;

您可以添加 where 子句。

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