2015-07-09 68 views
-1

我與SQL查詢轉換爲LINQLinq-加入,MAX(日)

SELECT * FROM Log x 
    JOIN (SELECT p.objId, 
       MAX(modifiedDateTime) AS latestDateTime 
      FROM Log p 
      GROUP BY p.objId) y ON y.objId= x.objId 
           AND y.latestDateTime = x.modifiedDateTime 

請建議掙扎。這是我到目前爲止的地方

var query1 = from x in query 
       join y in query 
       on new {x.objId, x.modifiedDateTime} 
       equals new {y.objId, ...(Max)} 

回答

1

您創建的兩個新匿名對象永遠不會相等。您需要直接比較這些值。嘗試: on x.objID等於y.objID & & x.modifiedDateTime等於y.lastestDateTime