I'm using Linq To Sql now, and how can I know how many queries was used to show the current page?
thank you very much
I'm using Linq To Sql now, and how can I know how many queries was used to show the current page?
thank you very much
The DataContext contains a TextWriter to write the generated SQL to if thats any help to you
DataContext.Log = System.Console.Out;
will output the generated SQL to the console
You can implement a textwriter and associate your new textwriter with the datacontext.log; when the datacontext tries to write you can update your counter.
If I were you, I will combine the DaveG solution(+1) with the Jan solution(+1).
You can put the association of the textwriter with the datacontext.log in the constructor of the DataContext, and use the #if preprocessor directive like this:
#if DEBUG
DataContext.Log = yourTextWriter.out;
#endif
This way will improve your performance in release mode.
You may want to try out my Linq-to-SQL profiler. You can read more, download it and get a free 45-day trial license from http://www.huagati.com/L2SProfiler/
It give you not only what queries were executed, but what code triggered them, what the I/O cost, db-side timings, even the db side execution plan. You can use it both during development and in production environments to log and profile L2S queries...
Also see this blog post: http://huagati.blogspot.com/2009/06/profiling-linq-to-sql-applications.html
I believe your best bet is write an HTTP module that would display the number of queries executed as well as the SQL that was generated at the bottom of each page. It's amazingly slick. I'm not going to write it out here for obvious reasons but pick up a copy of Steve Sanderson's book "Pro ASP.NET MVC Framework" and he walks you through it. The output looks like:
Executed 4 SQL queries
SELECT ...
UPDATE ...
UPDATE ...
UPDATE ...