Chapter 4. Working with Advanced Query Operators and Expressions

Chapter 3 provided examples of LINQ query expressions and method call syntax for Standard Query Operators (SQOs) by group. The data sources for queries were collections of relatively simple business objects. The objects included public fields of generic types and generic collections, but these fields were empty. The LINQ query expressions used Joins or GroupJoins to emulate relationships, where appropriate.

This chapter covers more complex LINQ queries over collections of object graphs that emulate real-world business entities, such as customers, orders, employees, suppliers, and products, by taking advantage of the relationships between the entities. Object graphs are tree-like representations for describing collections and instances of objects and hierarchies of their dependent and related objects. An object graph provides an internally consistent view of an application's data.

Much of this chapter is devoted to explaining complex aggregate queries that use the Count() and Sum() SQOs primarily, along with the Avg(), Min(), and Max() operators, with or without the join and grouping operators — Join(), GroupBy(), and GroupJoin(). You'll also see examples of left outer joins implemented by nested Select() and GroupJoin() queries.

Other advanced topics covered by this chapter are unconventional use of the Contains() SQO for widening Where clause filters and substitutes for T-SQL's IN() function, compiling specific types ...

Get Professional ADO.NET 3.5 with LINQ and the Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.