Lee
Lee

Reputation: 8744

Situations when stored procedures are appropriate when using an ORM like Entity Framework

I am looking for specific cases where stored procedures are a more appropriate choice than the default ORM functionality when using an ORM like Entity Framework. An example I have encountered is that ORMs are poor at bulk updates, usually generating a single update statement for each modified entity instead of an efficient single bulk update, so in this instance using the ORM for most CRUD operations, and a SP for the bulk update would make sense. What other situations are there where SPs are an appropriate choice when using an ORM?

Upvotes: 0

Views: 87

Answers (1)

Marek Grochowski
Marek Grochowski

Reputation: 143

Stored procedures can be individually secured within the database. A client can be granted permissions to execute a stored procedure without having any permissions on the underlying tables.

Stored procedures result in easier maintenance because it is generally easier to modify a stored procedure than it is to change a hard-coded SQL statement within a deployed component.

Stored procedures add an extra level of abstraction from the underlying database schema. The client of the stored procedure is isolated from the implementation details of the stored procedure and from the underlying schema.

Stored procedures generally result in improved performance because the database can optimize the data access plan used by the procedure and cache it for subsequent reuse.

And situation you described: Stored procedures can reduce network traffic, because SQL statements can be executed in batches rather than sending multiple requests from the client.

Upvotes: 1

Related Questions