Chapter 11. Working with functions and views

 

This chapter covers

  • Using defining queries
  • Creating custom database functions
  • Creating model defined functions

In the previous chapter, you saw that you can embed native SQL commands into the storage model of the EDM to simulate stored procedures. The same idea can be applied to create custom views that aren’t on the database. Creating such views can allow you to write simpler queries, easing the development process.

Another thing that eases querying is the use of database and model functions. These are pieces of code that can be reused across different queries, avoiding repetitive code. In Entity Framework 1.0, these functions could be used only via Entity SQL, but now they’re available in LINQ to Entities too. What’s even better, now you can create your own set of functions in the EDM, allowing further customization and even more reuse.

This chapter is all about these feature. First we’ll discuss embedding views in the EDM, and specifically the defining query feature, which is one of the most powerful, and hidden, features of Entity Framework. Then, we’ll talk about custom database functions and user-defined functions. By the end of this chapter, you’ll graduate from the university of the EDM.

Let’s first look at how you can embed views into the storage model.

11.1. Views in the storage model: defining queries

11.2. User-defined functions and scalar-valued functions

11.3. Summary