Chapter 9. An alternative way of querying: Entity SQL

 

This chapter covers

  • Executing queries using Entity SQL
  • Executing queries using query-builder methods
  • Using the Entity Client data provider

In this chapter, we’ll cover one of the hidden gems of Entity Framework: Entity SQL. LINQ to Entities has made this language almost obsolete, and developers don’t feel comfortable with it—its string-based nature is less expressive than the object-oriented LINQ. But thinking that Entity SQL is useless is a huge mistake, because some types of queries are easier to write using such a language.

In the first part of the chapter, we’ll discuss the querying capabilities of Entity SQL, focusing on different types of common operations, exactly as we did in chapter 4 when discussing LINQ to Entities. After that, we’ll explain how to easily use query-builder methods to use Entity SQL in combination with the ObjectContext. Later, we’ll talk about some advantages Entity SQL has over LINQ to Entities and look at the Entity Client data provider, which is the lowest level of Entity Framework and is used to interact almost directly with the database.

We’ll begin by looking at the basics of querying.

9.1. Query basics

9.2. Filtering data

9.3. Projecting results

9.4. Grouping data

9.5. Sorting data

9.6. Joining data

9.7. Querying for inheritance

9.8. Using query-builder methods

9.9. Working with the Entity Client data provider

9.10. Summary