O'Reilly logo

LINQ Pocket Reference by Joseph Albahari, Ben Albahari

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

Interpreted Queries

LINQ provides two parallel architectures: local queries for local object collections, and interpreted queries for remote data sources. So far, we’ve examined the architecture of local queries, which operate over collections implementing IEnumerable<>. Local queries resolve to query operators in the Enumerable class, which in turn resolve to chains of decorator sequences. The delegates that they accept—whether expressed in comprehension syntax, lambda syntax, or traditional delegates—are fully local to Intermediate Language (IL) code just as any other C# method.

By contrast, interpreted queries are descriptive. They operate over sequences that implement IQueryable<>, and they resolve to the query operators in the Queryable class, which emit expression trees that are interpreted at runtime.

Note

The query operators in Enumerable can actually work with IQueryable<> sequences. The difficulty is that the resultant queries always execute locally on the client—this is why a second set of query operators is provided in the Queryable class.

There are two IQueryable implementations in the .NET Framework:

  • LINQ to SQL

  • LINQ to Entities

In addition, the AsQueryable extension method generates an IQueryable wrapper around an ordinary enumerable collection. We describe AsQueryable in the upcoming “Building Query Expressions” section.

In this section, we’ll use LINQ to SQL to illustrate interpreted query architecture.

Note

IQueryable<> is an extension of IEnumerable<> with additional methods ...

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