-1

How to convert the following sql query to lambda expression?

SELECT Username, COUNT(Username) AS Count 
FROM user 
GROUP BY Username
1
  • try this: var grpUsers = empList.GroupBy(user => user.Username) .Select(lst => new {Username = lst.Key, Count = lst.Count()} ); Commented Jun 13, 2014 at 4:37

2 Answers 2

0
 var UserCount = yourEntityObject.GroupBy(m => m.Username)
                       .Select(c => new {Username = c.Key, Count = c.Count()});
Sign up to request clarification or add additional context in comments.

Comments

0

Try the following:

var grpUsers = empList.GroupBy(user => user.Username)
                         .Select(lst => new {Username = lst.Key, Count = lst.Count()} );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.