0

I have a SQL query that I need to turn into Linq but for the life of me I cannot seem to group the results.

This is the original SQL query:

select UserLevel, count(UserLevel) as count, StudioId
from UserProfile 
where CompletedSetup = 1 
and userid in (select UserId from webpages_UsersInRoles where RoleId = 4) 
group by StudioId, UserLevel
order by StudioId

and what it returns is something like

UserLevel     Count     StudioId
1             6         1
2             2         1
3             4         1
Riquelmy Melara
  • 849
  • 2
  • 11
  • 28

1 Answers1

0
context.UserProfile
.Where(x=>x.CompletedSetup==1 && context.webpages_UsersInRoles.Any(u=>u.UserId == x.UserId && u.RoleId == 4))
.GroupBy(x=>new {x.UserLevel, x.StudioId)
.Select(x=>new {UserLevel = x.Key.UserLevel, StudioId = x.Key.StudioId, count=x.Count()})
Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69