我有一個SQL語句,我試圖轉換爲LINQ查詢。我需要這樣做,因爲我不能編輯我的數據庫:(無論如何,我有一個SQL語句如下所示:LINQ - 嵌套查詢
SELECT
CustomerID,
FirstName,
LastName,
Gender,
BirthMonth,
(SELECT COUNT(ID) FROM PurchaseOrder WHERE [CustomerID]=CustomerID) as TotalPurchases
FROM
MyEntities
我知道該怎麼做的一切在LINQ除外的嵌套查詢部分目前,我有以下幾點:?
var results = from x in context.MyEntities
select new Customer()
{
CustomerID = x.CustomerID,
FirstName = x.FirstName,
LastName = x.LastName,
Gender = x.Gender,
BirthMonth = x.BirthMonth,
TotalPurchases = ?
};
如何執行在LINQ嵌套查詢來獲取TotalPurchases值
謝謝你這麼多