SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Entity Framework - Adhoc queries...


Entity Framework - Adhoc queries...

Author
Message
mortonsoft
mortonsoft
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 45
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.
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19172 Visits: 14900
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

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Chord77
Chord77
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 356
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
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5970 Visits: 5084
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,
SQL Server developer at Seavus
My blog: www.igormicev.com
Jack Corbett
  Jack Corbett
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19172 Visits: 14900
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

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Chord77
Chord77
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 356
Jack Corbett (7/15/2014)
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.


Thanks I'll keep my eye out for it as well. This could be very useful.
Cody Konior
Cody Konior
SSC-Addicted
SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)

Group: General Forum Members
Points: 443 Visits: 1105
Just wanted to point out I was looking at the result of a LINQ query last week that was causing a deadlock.

Update [Table] -- Ok
Set [Some Field] = @P1 -- Ok
Where
[Identity Column] = @P2 -- Great!
And [Other Column 1] = @P3
And [Other Column 2] = @P4
-- Stop!
...
And [Other Column 50] = @P52
-- No LINQ! Please, Stop!
...
And [Other Column 150] = @P152
-- What the hell just happened

Unfortunately the programmer couldn't correlate the SQL that was generated to the source of the LINQ code that caused it... so it's still out there. Somewhere. Causing harm.
Del Lee
Del Lee
Old Hand
Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)Old Hand (356 reputation)

Group: General Forum Members
Points: 356 Visits: 1302
Chord77 (7/15/2014)
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


Download the free ebook, T4 Succinctly by Nick Harrison. You can download after providing some basic information. You will get a phone call from Syncfusion after downloading, but it's nothing high pressure and they won't bother you again.



Del Lee
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search