4

このクエリを変換しようとしています (既に動作しています)

SELECT Building.NAME, COUNT([User].ID)
FROM BuildingUser
INNER JOIN Building ON Building.ID = BuildingUser.ID_BUILDING
INNER JOIN [User] ON [User].ID = BuildingUser.ID_USER
GROUP BY Building.NAME

Linq to SQL ですが、何が間違っているのかわかりません。私の努力を見て

from buildinguser in db.GetTable<BuildingUser>()
join building in db.GetTable<Building>()
on buildinguser.ID_BUILDING equals building.ID
join user in db.GetTable<User>()
on buildinguser.ID_USER equals user.ID
group building by building.NAME into grpBuilding
select new
{
    building = grpBuilding.Key,
    users = 
};

建物をグループ化し、各建物のユーザー数を数えるだけです。

4

1 に答える 1

9

Countメソッドを使用するだけです。

from buildinguser in db.GetTable<BuildingUser>()
join building in db.GetTable<Building>()
on buildinguser.ID_BUILDING equals building.ID
join user in db.GetTable<User>()
on buildinguser.ID_USER equals user.ID
group building by building.NAME into grpBuilding
select new
{
    building = grpBuilding.Key,
    users = grpBuilding.Count()
};
于 2013-07-20T01:36:40.280 に答える