使用linq连接两个表时出错,错误为The name 'u' does not exist in the current context
这是我的代码
from t in Teams
join u in Users on t.TeamId equals u.TeamId into g
where (t.TeamName.Contains("Pr")) && (t.Deleted != true) ||(u.FirstName.Contains("Ch"))
select new { t.TeamId,t.TeamName, t.Description,UserId=g.Count()}
答案 0 :(得分:1)
我已将其更改为先进行连接,然后对where进行过滤,然后进行分组。希望这有效:
from t in Teams
join u in Users on t.TeamId equals u.TeamId
where (t.TeamName.Contains("Pr")) && (t.Deleted != true) || (u.FirstName.Contains("Ch"))
group new { t.TeamId, t.TeamName, t.Description } by new { t.TeamId, t.TeamName, t.Description } into g
select new { g.Key.TeamId, g.Key.TeamName, g.Key.Description, UserId = g.Count() };