Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would I use an ORM if I am using Stored Procedures?

If I use stored procedures, can I use an ORM?

EDIT:

If I can use a ORM, doesn't that defeat part of the database agnosticity reason for using an ORM? In other words, why else would I want to use an ORM, if I am binding myself to a particular database with stored procedures (or is that assumption wrong)?

like image 298
johnny Avatar asked May 12 '09 21:05

johnny


People also ask

Can we use stored procedure in ORM?

Most ORMs can utilize stored procedures. Most ORMs generate Stored Procedures if you so choose.

When should you avoid ORM?

If you know your data access pattern is going to be complex or you plan to use a lot of database-specific features, you may not want to use an ORM.

When should I use an ORM?

Different database systems access data in myriad ways, and ORM helps you maintain objects even when the sources and apps they access change over time. ORM is commonly used to streamline the migration of data between databases.

Is ORM faster than stored procedure?

The bottom line is stored procedures using a DBMS's native SQL language can be orders of magnitude faster than ANY ORM generated SQL. However ORM approach is more maintainable. Most ORM devs are not experts at advanced SQL, and have no understanding/experience of this.


2 Answers

Using ORM to access stored procedures is one of the best uses of ORM. It'll give you strongly typed objects, while you still have full control over the SQL.

like image 78
Andomar Avatar answered Sep 17 '22 20:09

Andomar


In my experience I would let the ORM handle the 'CRUD' operations, and leave the specialty work to the stored procedures. Generally, using a stored procedure for 'CRUD' operations is overkill, and to let the ORM handle it, could drastically improve your productivity.

like image 25
drowe Avatar answered Sep 19 '22 20:09

drowe