Chapter 6. Using Stored Procedures with the EDM
Many databases use stored procedures to perform predefined logic on database tables. Although one of the key features of the Entity Framework is its ability to automatically build native commands based on your LINQ to Entities or Entity SQL queries, as well as the commands for inserting, updating, or deleting data, you may want to override these steps and use your own predefined stored procedures. Although the dynamically built commands are secure, efficient, and generally as good as or better than those you may write yourself, there are many cases where stored procedures already exist and your company practices may restrict direct use of the tables. Alternatively, you may just want to have explicit control over what is executed on the store and prefer to create stored procedures.
The sample database includes four stored procedures that we skipped in our discussion of model creation in Chapter 2. In this chapter, you will update the model, pulling in those four stored procedures, implementing them in the model, and interacting with them in some code.
In this chapter, you will override the Entity Framework’s command
generation feature for a particular entity and direct it to use your
stored procedures instead when
SaveChanges is called. The end of the chapter will also address the concept of combining entities that map to database views with stored procedures to provide fully functional entities to completely avoid direct database access. ...