linq2sql复杂查询(计数问题)
本文关键字:问题 复杂 查询 linq2sql | 更新日期: 2023-09-27 18:06:50
好的,我正试图编写一个查询来获取每个区域的总访客数,到目前为止我失败了:)
var Results = from g in DB.tblSecurityZones
join PoliceStations in DB.tblPoliceStations
on g.SecurityZoneID equals PoliceStations.SecurityZoneID
join Hotel in DB.tblHotels
on PoliceStations.PoliceStationID equals Hotel.PoliceStationID
join HotelGuest in DB.tblGuests
on Hotel.HotelID equals HotelGuest.HotelID
group g by new
{
Zone = g.Name,
PoliceStation = PoliceStations.Name,
Hotel = Hotel.HotelName
} into Result
select new
{
Result.Key.Hotel,
Result.Key.PoliceStation,
Result.Key.Zone
};
我想要的是从每个区域返回客人计数。
我得到了HotelName, PoliceStationName和ZoneName,但我不知道如何获得GuestCounts也:S
select new
{
Result.Key.Hotel,
Result.Key.PoliceStation,
Result.Key.Zone,
Count = Result.Count()
};