Skip to content

Codepolice

  • ⤫

Group By with LINQ

Posted by Judy Alvarez Posted on February 25, 2022March 3, 2022
0

Today I wanted to do a group-by query with LINQ which is something I did before. It turned out to be kind of easy.

If you just want to group by a single field.

(from s in db.CrewStatsSet
where s.LogDate >= date1 && s.LogDate <= date2 && s.Action == action
group s by s.User.nick into g
orderby g.Count() descending
select new CrewStatsData
{
    Nick = g.Key,
    Count = g.Count(),
}).ToList();

And if you need to group by multiple fields.

(from s in db.CrewStatsSet
where s.LogDate >= date1 && s.LogDate <= date2 && s.Action == action
group s by new { s.User.nick, s.Action, s.User.userID } into g
orderby g.Count() descending
select new CrewStatsData
{
    Nick = g.Key.nick,
    Count = g.Count(),
    ActionId = g.Key.Action,
    UserId = g.Key.userID
}).ToList();
Categories: JavascriptTagged: .net mvc solutions, asp net 5 mvc 6, asp net mvc 6 tutorials, asp net mvc barcode scanner, asp net mvc book, asp net mvc create pdf, asp net mvc datagrid, asp net mvc download, asp net mvc example, asp net mvc html to pdf, asp net mvc interview questions for experienced, asp net mvc mobile application development, asp net mvc security, asp net mvc vs php, crud asp net mvc, difference between .net core and mvc, difference between mvc and net core, dot net developer mvc angular, dot net tricks mvc, net mvc vs net core

Post navigation

Previous Previous post: Join and Group By with LINQ to Entities
Next Next post: Finally have Subversion + CruiseControl.NET + MSBuild running

Related Posts

  • Bringing Python apps into Node

    #​596 — October 14, 2025 Read on the Web 📂 A Modern Guide to Reading and Writing Files in Node — A comprehensive guide to various methods for working with files, from promise-based methods through to working with streams, processing files concurrently, using file handles, and memory-efficient techniques. Luciano Mammino A Way to Integrate Python ASGI with Node.js

    Posted by Posted on October 14, 2025
    0
  • Vite gets its own documentary

    #​756 — October 10, 2025 Read on the Web JavaScript Weekly ▶  Vite: The Documentary — From the same creators of the fantastic ▶️ Node.js, ▶️ Angular and ▶️ React documentaries comes an up to date look at Vite, the build tool that has taken the JavaScript ecosystem by storm in recent years. Many luminaries make an appearance to

    Posted by Posted on October 10, 2025
    0
  • npm security best practices to consider

    #​595 — October 7, 2025 Read on the Web 15 Recent Node Features That Can Replace Popular npm Packages — Many features that once required third-party packages are now built into the runtime itself. Here’s a look at some of the most notable that you may want to experiment with, prior to reducing unnecessary dependencies. Lizz

    Posted by Posted on October 7, 2025
    0
  • React 19.2 is in the building

    #​755 — October 3, 2025 Read on the Web JavaScript Weekly The State of JavaScript 2025 Survey — Each year, Devographics runs an epic survey of as many JavaScript community members as it can and turns the results into an interesting report on the state of the ecosystem – here’s the results from 2024. If

    Posted by Posted on October 3, 2025
    0
  • Using Node with Cloudflare Workers

    #​594 — September 30, 2025 Read on the Web 🗓️ We’re back after taking a week off for my birthday. I’ve never bothered to do that before, but I figured I’d give it a go, and.. it was good 😅 We’re now back every week until Christmas!__Peter Cooper, your editor A Year of Improving Node.js

    Posted by Posted on September 30, 2025
    0
  • The first browser with JavaScript landed 30 years ago

    #​754 — September 26, 2025 Read on the Web JavaScript Weekly Give Your AI Eyes: Introducing Chrome DevTools MCP — The Chrome team has released an MCP server for Chrome DevTools, enabling agents like Claude Code or OpenAI Codex to use the DevTools to debug and analyze the performance and behavior of your webapps (or

    Posted by Posted on September 26, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • Bringing Python apps into Node
  • Vite gets its own documentary
  • npm security best practices to consider
  • React 19.2 is in the building
  • Using Node with Cloudflare Workers
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice