1
我想要得到的計數,即使計數爲0或不LINQ GROUP BY。這是我的linq組合。在foreach循環中,如果var g中沒有計數,則循環。我想得到這個變數,即使計數爲0LINQ組由數
var x = from b in context.Bookings
where b.FlightID == f.FlightID
group b by b.FlightID into g
select new
{
Count = g.Count()
};
foreach (var g in x)
{
var c = (from a in context.Aeroplanes
where a.AeroplaneID == f.AeroplaneID
select a.Capacity).First();
int capacity = c;
int i = g.Count;
if (capacity - i >= NoOfPass)
{
returnList.Add(f);
}
}
謝謝兄弟,我知道了,因爲烏拉圭回合的答案。 –
以下是有效的,將是更優雅:'context.Bookings.Count(B => b.FlightID == f.FlightID)' – mazharenko
此外,我覺得你的意思的選擇B,而不是選擇X –