Aggregate Queries
LINQ to SQL supports the Average
, Count
, Max
, Min
, and Sum
aggregate operators. Note the following characteristics of aggregate operators in LINQ to SQL:
Aggregate queries are executed immediately.
For more information, see Introduction to LINQ Queries (C#).
Aggregate queries typically return a number instead of a collection.
For more information, see Aggregation Operations.
You cannot call aggregates against anonymous types.
The examples in the following topics derive from the Northwind sample database. For more information, see Downloading Sample Databases.
In This Section
Return the Average Value From a Numeric Sequence
Demonstrates how to use the Average operator.
Count the Number of Elements in a Sequence
Demonstrates how to use the Count operator.
Find the Maximum Value in a Numeric Sequence
Demonstrates how to use the Max operator.
Find the Minimum Value in a Numeric Sequence
Demonstrates how to use the Min operator.
Compute the Sum of Values in a Numeric Sequence
Demonstrates how to use the Sum operator.
Related Sections
Query Examples
Provides links to LINQ to SQL queries in Visual Basic and C#.
Query Concepts
Provides links to topics that explain concepts for designing LINQ queries in LINQ to SQL.
Introduction to LINQ Queries (C#)
Explains how queries work in LINQ.