{
  "id": 10775522,
  "title": "LINQ Aggregate Operators: Beyond Sum and Count",
  "url": "https://urgent.news/2026/09/29/linq-aggregate-operators-beyond-sum-and-count",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-29T20:35:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/homolibere/linq-aggregate-operators-beyond-sum-and-count-8l7"
  },
  "original_language": "en",
  "account": "LINQ aggregate operators extend beyond the basic Sum and Count functions, offering a powerful tool for custom reductions. The Aggregate() operator can implement any aggregation, including custom ones.\n\nBasic LINQ aggregate functions like Count(), Sum(), Average(), Min(), and Max() translate to SQL aggregates, executing efficiently in the database. However, when the sequence is empty, Sum() and Count() handle this gracefully by returning 0, while the others throw an InvalidOperationException.\n\nTo avoid this exception, nullable overloads can be used, returning null instead of an error. This matches SQL behavior, where SELECT AVG(Price) FROM Products WHERE 1=0 returns NULL. The nullable overloads provide SQL-like semantics when needed.\n\nNew in .NET 6 are MinBy and MaxBy methods, which return the element with the minimum or maximum value, respectively, rather than the value itself. This is more efficient as it requires only one iteration. However, these methods are specific to LINQ to Objects and not supported by EF Core.\n\nThe Aggregate() function is a versatile tool that can build any aggregation, taking a seed value, a combining function, and optionally a result selector. For example, it can manually implement a sum or product calculation.",
  "summary": "LINQ Aggregate Operators: Beyond Sum and Count Everyone knows Count() and Sum() . But LINQ's aggregate family goes deeper — and the general-purpose Aggregate() operator can implement any of them, plus custom reductions you haven't imagined yet. Let's explore what's beyond the basics. The Usual Suspects var products = dbContext . Products ; var count = products . Count (); // Number of items var…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}