需要将带有 COUNT 的 SQL 联接查询转换为 LINQ 并将其传递给视图
本文关键字:LINQ 视图 转换 COUNT SQL 查询 | 更新日期: 2023-09-27 18:29:10
select COUNT([User].UserId)
from [User] join Team on [User].TeamId = Team.TeamId where Team.TeamId =2
这是我到目前为止所拥有的,但我无法弄清楚如何实现
var countUser = from u in db.Users
join t in db.Teams
on u.TeamId equals t.TeamId
where (u.TeamId == 11)
select new
{
};
试试这个
var countUser = (from u in db.Users
join t in db.Teams
on u.TeamId equals t.TeamId
where (u.TeamId == 11)
select new
{
u.UserId
}).Count();