r.zarei
r.zarei

Reputation: 1261

Using stored procedure with Entity Framework or not?

I want to know, do I use stored procedure with Entity Framework or just user Linq-to-Entities queries?

Consider I want have a customer's orders. So one solution achieved by using stored procedure that uses joins on two table and for example return order IDs.

Another solution achieved by using Linq-to-Entities queries. This solution have a preference over first solution and that is, we can user navigation properties to easily move in customer order information. but in stored procedure since it only return ID's it's a little bit to access order information.

So which is better, considering second solution preference?

Upvotes: 1

Views: 1150

Answers (1)

marc_s
marc_s

Reputation: 754548

Both solutions work - and since you didn't define what "better" means to you, we cannot possibly tell you which solution is "better".

Using stored procedures with Entity Framework is definitely possible - especially with EF4. Stored procedure have their benefits - you don't have to give the user direct table access, you can possibly let a DBA tweak those stored procs for top performance, and you can do things like delete a Customer by just calling a stored proc with the CustomerID to delete (instead of having to first load the whole customer, just to delete it).

So stored procedures definitely have benefits - the downside to many folks is that they have to write those in T-SQL, and now suddenly part of your application is in your C# code, while another part is in stored procedure's T-SQL code.

So again: as vague as you asked, there's no real good answer to this. Both approaches are valid and both work - it's a bit of a personal preference, which one you want to use.

Upvotes: 3

Related Questions