0
如何將此SQL語句轉換爲LINQ,效率最高?此SQL到LINQ
SELECT categoryName,
(SELECT COUNT(*) cnt
FROM itemCategories
WHERE (categories.categoryId = itemCategories.categoryId)
AND (Items.countryPartId = 1)) AS cnt
FROM categories, Items
這是LINQ查詢我有現在:
var q =
from c in context.categories
select new CategoryCount
{
CategoryName = c.categoryName,
Counter = (
from i in context.itemCategories
where c.categoryId == i.categoryId
select i).Count()
};
這是LINQ子句而不與WHERE子句中: VAR Q =(從C中context.categories \t選擇新CategoryCount \t { \t類別名稱= c.categoryName, 計數器= (from i in context.itemCategories where c.categoryId == i.categoryId select i).Count() }); – danielovich 2010-12-06 12:03:33