views:

248

answers:

7

I have a couple of LINQ to SQL queries that I feel take a lot of time. What tool and techniques can I use to first find out:

  1. How long they take and if there is room for improvement?
  2. Find out what I can change and easily test if those changes are effective?

Both tools, techniques and reading resources would be appreciated (ergo up-voted ;))

+2  A: 

Well, the best option probably still is the SQL Server Profiler, which will give you an in-depth look at what's going on at SQL Server's end of the wire. This is based on the assumption (backed by my own experience) that most often than not, the real problem for the performance lies more on the database backend and suboptimal indices and db design rather than the "front-end" LINQ queries...

See:

Marc

marc_s
+4  A: 

I would check this blog t out by David Hayden...

Robban
+1 excellent stuff! Thanks for that link
marc_s
A: 

This previous post may give you some help.

Alfred Myers
+6  A: 

LinqPad can be helpful. Used in conjunction with SQL profiler you might be able to work out what is going on and how it can be improved.

Simon P Stevens
+6  A: 

I just attended a LINQ Tools presentation at a recent codecamp event given by Jim Wooley, one of the authors of LINQ In Action. He blogged about all the tools. Here are the ones that relate to your question, but his post lists other goodies to look into.

  • SQL Server Profiler ($$$) - part of the SQL Management Studio.

  • Huagati LINQ to SQL Profiler ($$$, 45-day trial) - Profiler which extends the Context.Log functionality. Includes performance and call stacks for the queries beyond what you get with SQL Server Profiler.

  • LINQ to SQL Visualizer (free) - part of the C# Samples for VS2008. Download, compile, enjoy!

  • LINQPad (free, pay for C# Intellisense) - light-weight tool to run C#/VB.NET code, connect to DBs, test Linq to SQL, view the generated SQL etc.

Ahmad Mageed
Very good! Thanks! Lots of new ones in there for me.
Riri
Be sure to check out Jim's blog post for other neat tools. I just added that info to my post :)
Ahmad Mageed
Very nice answer. LinqPad is the best of the bunch.
Rap
+1. :) I just want to add that Huagati Linq-to-SQL Profiler can be used for 45 days for free (free trial). Also, some background and usage examples here: http://bit.ly/kzOxw and here: http://bit.ly/2Yg1EC
KristoferA - Huagati.com
@KristoferA: good info, thanks for sharing. It looks like you're involved with the tool, nice work! :)
Ahmad Mageed
@Ahmad Mageed: Thanks. :) Yep, I'm involved with the tool... (I wrote it :) ).
KristoferA - Huagati.com
A: 

One nice "trick" when using LINQ to SQL is to use the DataContext.Log property to see the SQL generated by the framework:

context.Log = Console.Out

SQL Server Profiler will give you a more objective measure of the performance of your queries, but being able to inspect the queries directly may still reveals some unexpected information.

Martin Liversage
+1  A: 

The amazing Linq to Sql Profiler by Hybernating Rhinos. You get real-time analysis of your code and alerts indicating patterns of misuse. 30 day trial.

Lee Treveil