views:

70

answers:

1

Hi, I had a look at EF 4 (Entity Framework) from MS (notice I am a beginner :-). I understand its use for separation of Layer Logic as DAL.

In EF 4 I see it is possible to create code for query the Data Base, query are stored in DAL.

My questions is what could be the benefit of using SPROC with EF 4?

To me calling SPROC from the EF 4 seems not maintaining a clear division between layers.

Any 'gotchas' on topic of best practice for EF 4 and SPROC?

Thanks guys your usual great support!

+1  A: 

There are a few reasons why you might want to use EF with stored procedures. First, your company's DBA might require all stored proces (granted, this is a different debate but unfortunately sometimes you're not given a choice) - in this case using EF with stored procedures still allows you to use the rich mapping framework and save yourself from writing a ton of code wiring up columns to properties.

Also, ORM's like EF are great at modeling your typical CRUD operations. However, you might have a very complex query where it's easier to model it with straight SQL than an EF query. In this case a sproc would be desirable as well (and still you're leveraging the EF mapping capabilities).

Steve Michelotti
Hi Steve , thanks for your comment, do you know if EF 4 has come features against SQL INJECTION? thanks
GIbboK
Yes, EF will automatically guard against SQL injections by internally parameterizing the variables in the SQL.
Steve Michelotti
Once again thanks!
GIbboK
Sorry Steve, May I ask another questions? Regarding performance and cache of queries... EF 4 can cache queries (esql)??? thanks :-)
GIbboK
Yes. Plus, SQL server will cache the query plan as well. Check this out for EF performance: http://msdn.microsoft.com/en-us/library/cc853327.aspx
Steve Michelotti