O'Reilly logo

Programming Entity Framework, 2nd Edition by Julia Lerman

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 7. Using Stored Procedures with the EDM

Many databases use stored procedures to perform predefined logic on database tables, and many organizations have policies in place that require the use of these stored procedures. 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 build 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 six 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 six 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. You’ll also learn how to incorporate and use procedures that return data. The chapter will also address ...

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