我正在尝试转换此查询(已经工作)
select [User].ID AS ID_USER
from [User]
right join Building on Building.ID = 4 AND
Building.ID_USER_RESPONSIBLE <> [User].ID
where [User].ID_MANAGER = 1
到Linq to SQL,但我不知道我做错了什么。看看我的努力
IList<User> lstUser = (from building in db.GetTable<Building>()
join user in db.GetTable<User>()
on new
{
ID_BUILDING = building.ID,
ID_USER = building.ID_USER_RESPONSIBLE
}
equals new
{
ID_BUILDING = 4,
ID_USER != user.ID
} into grpUser
from grp in grpUser.DefaultIfEmpty()
where building.ID_MANAGER = 1
select new
{
ID_USER =
});
我需要退回所有用户以及不对任何建筑物负责的用户;
编辑
此处发布的任何解决方案都有效。我已经解决了这样做:
var lstUser = (from building in db.GetTable<Building>()
join user in db.GetTable<User>()
on building.ID equals 4
where user.ID_MANAGER == 1 &&
building.ID_USER_RESPONSIBLE != user.ID
select new
{
ID_USER = user.ID,
NAME = user.NAME
}).ToList();