我有一個讓GROUP BY正常工作的問題。有人能看到爲什麼嗎?Linq:group by不工作
public void MonthlyTurnover(int year, int month) {
var q1 = (from sp in _db.Species
from p in _db.Pets
from b in _db.Bookings.Where(x => x.ExpectedArrivalTime.Year == year &&
x.ExpectedArrivalTime.Month == month)
where p.SpeciesId == sp.Id && b.PetId == p.Id && b.PetId == p.Id
select new {sp.SpeicesName, Sum = b.Services.Sum(i => i.Price)}).ToList();
foreach (var v in q1) {
Console.WriteLine(v);
}
}
我能得到什麼,而不按
public void MonthlyTurnover(int year, int month) {
var q1 = (from sp in _db.Species
from p in _db.Pets
from b in _db.Bookings.Where(x => x.ExpectedArrivalTime.Year == year &&
x.ExpectedArrivalTime.Month == month)
where p.SpeciesId == sp.Id && b.PetId == p.Id && b.PetId == p.Id
select new {sp.SpeicesName, Sum = b.Services.Sum(i => i.Price)})
.GroupBy(x => new{x.SpeicesName, x.Sum}).ToList();
foreach (var v in q1) {
Console.WriteLine(v.Key);
}
}
什麼我與一羣由
,我想什麼...
謝謝,那正是我需要:) – user3389475
不客氣,很高興爲你提供幫助;) – octavioccl