我需要将以下查询转换为 linq 或 lambda 表达式
SELECT count(Hid.HouseholdID) FROM
(SELECT HouseholdID FROM tblTmpJoinAll
WHERE loyal = 1 Group By HouseholdId
HAVING Count(distinct BasketID)>1) as Hid;
到目前为止,我已经尝试了
lst.Where(f => f.Flybuys == true)
.GroupBy(h=>h.HouseholdID)
//.Where(x=>x.)// don't know what to right here
.Select(h => h.Key).Count();
答案 0 :(得分:3)
我认为此代码有效。
lst.Where(f => f.Flybuys) // you don't need == true here
.GroupBy(f => f.HouseholdID)
.Where(f => f.GroupBy(i => i.BasketID).Count() > 1)
.Count();