I am very interested in a definitive answer here... In a shop like mine where they don't want any stored procs to be used at all, and where they believe that having an in-house DBA is a waste of money (I'm not even kidding), how does one make a convincing argument for stored procs? They are .NET developers who know a bit of SQL; I am a SQL developer and former DBA who was hired to do .NET. I can tell them all of the advantages of stored procs -- protection against SQL injection, greater speed if well-written, quicker deployment -- but I don't know enough about Entity Framework to be able to give them the down sides in a confident way when comparing Entity Framework (with direct mapping) to stored procs...
mortonsoft (7/9/2014)
I am very interested in a definitive answer here... In a shop like mine where they don't want any stored procs to be used at all, and where they believe that having an in-house DBA is a waste of money (I'm not even kidding), how does one make a convincing argument for stored procs? They are .NET developers who know a bit of SQL; I am a SQL developer and former DBA who was hired to do .NET. I can tell them all of the advantages of stored procs -- protection against SQL injection, greater speed if well-written, quicker deployment -- but I don't know enough about Entity Framework to be able to give them the down sides in a confident way when comparing Entity Framework (with direct mapping) to stored procs...
This is a very old thread and there have been many positive changes to EF since this thread was active. For example, in my previous post I said:
I have not used EF yet, but have done a little with Linq to SQL which is somewhat similar, although not as robust. One of the issues with Linq to SQL is that it passes string parameters using their length so that Select * from person where first_name = 'Bob' and Select * From person where first_name = 'Steve' generate 2 query plans because it parameterizes the call and sends a varchar(3) parameter the first time and varchar(5) the second time and it may also be nvarchar so if your column is varchar you have an implicit conversion taking place as well.
This is no longer true. The last time I looked it sent string parameters as either varchar(8000) or nvarchar(4000) which means that cached plans can be re-used.
A few concerns I would still have would be:
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.
2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
ORM tools like EF can be great at simple CRUD and simplify those pieces, but there is a cost down the line. Most places I've worked have been willing to put off the cost to later to deliver quickly. It hasn't always work out the best, but it can be hard to convince management to wait a bit to save time later.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Jack Corbett (7/9/2014)
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
Agreed on all points. I'm busy tuning a system which uses EF and thousand line long SQL statements are the norm, queries which fetch every column from the table, queries which fetch every row from multiple tables in a set of UNIONS, etc. Half the queries all I can do is send them to the dev and ask what the point is and whether they can be moved to stored procs.
EF is fine for simple queries. Sure beats writing a few hundred CRUD procedures.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
GilaMonster (7/9/2014)
Jack Corbett (7/9/2014)
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
Agreed on all points. I'm busy tuning a system which uses EF and thousand line long SQL statements are the norm, queries which fetch every column from the table, queries which fetch every row from multiple tables in a set of UNIONS, etc. Half the queries all I can do is send them to the dev and ask what the point is and whether they can be moved to stored procs.
EF is fine for simple queries. Sure beats writing a few hundred CRUD procedures.
Thanks, Jack and GM -- this was very, very helpful.
mortonsoft (7/14/2014)
GilaMonster (7/9/2014)
Jack Corbett (7/9/2014)
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
Agreed on all points. I'm busy tuning a system which uses EF and thousand line long SQL statements are the norm, queries which fetch every column from the table, queries which fetch every row from multiple tables in a set of UNIONS, etc. Half the queries all I can do is send them to the dev and ask what the point is and whether they can be moved to stored procs.
EF is fine for simple queries. Sure beats writing a few hundred CRUD procedures.
Thanks, Jack and GM -- this was very, very helpful.
Just a note about having to write CRUD procedures. With the March release of SSDT, you can now use T4 templates to generate all your basic CRUD procedures, so once you have written a template for that the creation of CRUD procs takes seconds.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Jack Corbett (7/14/2014)
mortonsoft (7/14/2014)
GilaMonster (7/9/2014)
Jack Corbett (7/9/2014)
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
Agreed on all points. I'm busy tuning a system which uses EF and thousand line long SQL statements are the norm, queries which fetch every column from the table, queries which fetch every row from multiple tables in a set of UNIONS, etc. Half the queries all I can do is send them to the dev and ask what the point is and whether they can be moved to stored procs.
EF is fine for simple queries. Sure beats writing a few hundred CRUD procedures.
Thanks, Jack and GM -- this was very, very helpful.
Just a note about having to write CRUD procedures. With the March release of SSDT, you can now use T4 templates to generate all your basic CRUD procedures, so once you have written a template for that the creation of CRUD procs takes seconds.
I am interested in this, are there any good resources for learning more about T4 templates? (A quick search shows lots of questions asking about T4 templates)
Thanks
GilaMonster (7/9/2014)
Jack Corbett (7/9/2014)
1. Scaling - ORM tools still aren't very good at complex SQL (multiple joins, outer joins, etc...) so you need to evaluate every query that EF is sending and be ready to replace "bad" queries with stored procedures.2. Tight coupling - if you really want to take full advantage of EF or any other ORM toll it means that you are tightly coupling the data access layer to your database. That means you are stuck with a specific database design until you can change the application as well. Whereas a design that provides an "API" to the database via views/functions/procedures allows you to change the underlying schema of the database as long as your API presents the same shape data to the application.
3. Tuning - if there is a poorly performing query there is little you can do to tune it. The SQL is generated so, AFAIK, you can't provide hints (OPTION (RECOMPILE) to help with "bad" parameter sniffing) or re-shape it to get a different plan.
Agreed on all points. I'm busy tuning a system which uses EF and thousand line long SQL statements are the norm, queries which fetch every column from the table, queries which fetch every row from multiple tables in a set of UNIONS, etc. Half the queries all I can do is send them to the dev and ask what the point is and whether they can be moved to stored procs.
EF is fine for simple queries. Sure beats writing a few hundred CRUD procedures.
I also had the chance to tune EF systems. Same as you describe.
Because I didn't want to ask for many of the queries I realized that extending some of the non-clustered indexes have brought a lot of improvement for bunch of queries.
Anyway there is an "optimize for ad hoc workloads" option. It enables query plans to use less memory when cached.
Igor Micev,My blog: www.igormicev.com
Chord77 (7/15/2014)
I am interested in this, are there any good resources for learning more about T4 templates? (A quick search shows lots of questions asking about T4 templates)
Thanks
There isn't a lot out there for T4 tempates with SSDT because it is so new. The only blog post I've found is this, http://dataidol.com/davebally/2014/03/29/t4-support-in-ssdt/ and it is very basic. I'm keeping my eye out for the video to be posted of this SQLBits Session scheduled to be presented this Saturday, http://www.sqlbits.com/Sessions/Event12/T4_Templating_within_SSDT_using_SQL_Server_2014, as I'm hoping this helps clear up some questions I have as to how to best incorporate T4 templates in my projects.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply