我有一个让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