Aggregate Queries (LINQ to SQL)
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.
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 (LINQ to SQL).
In This Section
How to: Return the Average Value from a Numeric Sequence (LINQ to SQL)
Demonstrates how to use the Average operator.How to: Count the Number of Elements in a Sequence (LINQ to SQL)
Demonstrates how to use the Count operator.How to: Find the Maximum Value in a Numeric Sequence (LINQ to SQL)
Demonstrates how to use the Max operator.How to: Find the Minimum Value in a Numeric Sequence (LINQ to SQL)
Demonstrates how to use the Min operator.How to: Compute the Sum of Values in a Numeric Sequence (LINQ to SQL)
Demonstrates how to use the Sum operator.
Related Sections
Query Examples (LINQ to SQL)
Provides links to LINQ to SQL queries in Visual Basic and C#.Query Concepts in LINQ to SQL
Provides links to topics that explain concepts for designing LINQ queries in LINQ to SQL.Introduction to LINQ Queries
Explains how queries work in LINQ.