Click here to Skip to main content
Click here to Skip to main content

See the SQL Generated by LINQ

By , 26 Feb 2010
 
When using LINQ to SQL, it can be very useful to see the SQL commands that are generated by your LINQ expressions. Sometimes the results are surprising and you might be able to improve performance by tweaking the LINQ.
 
All you have to do is set the Log property of the DataContext object. For example.
 
MyDataContext.Log = Console.Out;
 
This will cause the SQL commands generated by MyDataContext to appear in the output window in the debugger. You probably shouldn't leave this in your code without at least wrapping a #if DEBUG around it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

MarkLTX
Software Developer (Senior)
United States United States
Member
Mark Lauritsen has been a software developer for as long as he can remember.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberfakeer muhammed10 Feb '13 - 4:39 
GeneralMy vote of 5memberCarsten V2.021 Jun '12 - 8:57 
GeneralReason for my vote of 5 Straight to the point and provides a...memberBrianBissell26 Jul '11 - 4:28 
GeneralReason for my vote of 5 Very simple and effective.memberPravin Patil, Mumbai18 Jul '11 - 23:57 
Generalnice and easy. Great!memberMember 414818817 Apr '11 - 19:39 
GeneralReason for my vote of 5 Good to knowmemberAlomgir Miah A12 Apr '11 - 8:55 
GeneralIs there anything like this for Entity Framework?memberIgor Merabishvili11 Apr '11 - 21:36 
GeneralReason for my vote of 5 Thank you for the simple solution wh...memberlinuxjr7 Apr '11 - 17:30 
GeneralReason for my vote of 5 This is so simple it makes me puke a...protectorAspDotNetDev7 Apr '11 - 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130513.1 | Last Updated 26 Feb 2010
Article Copyright 2010 by MarkLTX
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid