linq - C# query with count -


i have list of users having several properties , want know , how had same code (which user property)

for example :

  • user 1: jacob, code 1
  • user 2: charlie, code 1
  • user 3: thomas, code 2

i need query , have result :

+--------+--------+ | object |  count | +--------+--------+ | user 1 |    2   | | user 2 |    2   | | user 3 |    1   | +--------+--------+ 

"2" because 2 users have same code , "1" because 1 had code

can me please?

you can using linq. change tablename , field name according yours.

(from user in _context.users              let count = _context.users.where(p=>p.code == user.code).count()                  select new {user.username, count = count}).tolist() 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -