我有我需要轉換爲LINQ這個SQL查詢:什麼是LINQ中SQL的最大功能等價物?
SELECT *
FROM USER U
INNER JOIN (
SELECT USERID , MAX(SALESDATE) AS MAXDATE
FROM SALES
GROUP BY USERID) S ON U.ID = S.USERID
到目前爲止,這是我想出LINQ:
var Users = (from d in db.Users
join s in db.Sales on d.Id equals s.UserId
select new Models.User
{
Id = d.Id,
UserName = d.UserName,
FirstName = d.FirstName,
LastName = d.LastName,
EmailAddress = d.EmailAddress,
PhoneNumber = d.PhoneNumber,
LastPurchase = s.SalesDate
}).Max(x => x.SalesDate);
不過,我敢肯定結果是不一樣的。任何人都可以建議將其轉換爲LINQ的正確方法嗎?我還是學習LINQ的新手。我非常感謝幫助。