O'Reilly logo

Professional ADO.NET 3.5 with LINQ and the Entity Framework by Roger Jennings

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required