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

  • Playwright now offers a UI mode

    #​631 — March 24, 2023 Read on the Web JavaScript Weekly Speeding Up the JavaScript Ecosystem: npm Scripts — The latest in what has been a fascinating series on finding ‘low hanging fruit’ when it comes to performance in the JavaScript world. The author explains it best himself: “‘npm scripts’ are executed by JavaScript developers

    Posted by Posted on March 24, 2023
    0
  • Everyone’s coming for Node.js this week

    #​479 — March 23, 2023 Read on the Web 🔒  npm Granular Access Tokens Now Generally Available — The granular access token feature on the npm registry is now generally available, allowing you to restrict token access to specific packages, set expiration dates, limit access by IP range, and more. GitHub Automatic npm Publishing with GitHub

    Posted by Posted on March 23, 2023
    0
  • Transformers: JavaScript in Disguise

    #​630 — March 17, 2023 Read on the Web JavaScript Weekly 🤖  Transformers.js: Running ML Models in the Browser — Transformers are a type of machine learning model often used for natural language or visual processing and while running such models directly in the browser is in its infancy, Transformers.js opens up some ML models

    Posted by Posted on March 17, 2023
    0
  • Shell-free scripting from Node

    #​478 — March 16, 2023 Read on the Web Shell-Free Scripts with Execa 7.1 — Execa is a popular process execution library for Node and the latest version includes an interesting $ method feature for writing zx-style scripts with it, making it even more useful for shell scripting style usecases. ehmicky Turbowatch: File Change Detector and

    Posted by Posted on March 16, 2023
    0
  • New JavaScript features of the past few years

    #​629 — March 10, 2023 Read on the Web JavaScript Weekly JavaScript Features from the Past Few Years — Packed with examples, this post tackles the changes and tweaks to JavaScript and TypeScript over the past several years (some as far back as ES6/ES2015, like tagged template literals). Linus Schlumberger Astro’s 2023 Web Framework Performance Report —

    Posted by Posted on March 10, 2023
    0
  • Taking flight with Feathers 5

    #​477 — March 9, 2023 Read on the Web Feathers 5: The API and Real-Time App Framework — Feathers isn’t as well known as Nest or Fastify, say, but it’s a powerful and mature option if you want to spin up a Node CRUD app tied to a database and now it’s “TypeScript all the

    Posted by Posted on March 9, 2023
    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
  • Playwright now offers a UI mode
  • Everyone’s coming for Node.js this week
  • Transformers: JavaScript in Disguise
  • Shell-free scripting from Node
  • New JavaScript features of the past few years
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice