需要将带有count的sql join查询转换为linq并将其传递给view

时间:2014-11-04 17:40:24

标签: c# sql-server asp.net-mvc linq

 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
                            {
                            };

1 个答案:

答案 0 :(得分:0)

试试这个

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();