2016-03-10 47 views
0

任何人都可以幫助我嗎?我不能給下面的表達式轉換在SQL等效Lambda表達式,Lambda在SQL的from子句中加入「<>」的等效表達式

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; 

回答

1

你可以添加一個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 
+0

我們可以使用ON刪除所有檢查並在where子句中進行所有檢查。這兩種方式是否相同? – shomaail

+1

Where子句和On子句之間存在差異b/w條件http://stackoverflow.com/questions/8311096/whats-the-difference-between-where-clause-and-on-clause-when-table-left -加入 – shomaail

相關問題