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

Tagged as

See the SQL Generated by LINQ

, 26 Feb 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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. ...
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)

Share

About the Author

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

Comments and Discussions

 
GeneralMy vote of 1 Pinmemberfakeer muhammed10-Feb-13 5:39 
GeneralMy vote of 5 PinmemberCarsten V2.021-Jun-12 9:57 
GeneralReason for my vote of 5 Straight to the point and provides a... PinmemberBrianBissell26-Jul-11 5:28 
GeneralReason for my vote of 5 Very simple and effective. PinmemberPravin Patil, Mumbai19-Jul-11 0:57 
Generalnice and easy. Great! PinmemberMember 414818817-Apr-11 20:39 
GeneralReason for my vote of 5 Good to know PinmemberAlomgir Miah A12-Apr-11 9:55 
GeneralIs there anything like this for Entity Framework? PinmemberIgor Merabishvili11-Apr-11 22:36 
GeneralReason for my vote of 5 Thank you for the simple solution wh... Pinmemberlinuxjr7-Apr-11 18:30 
GeneralReason for my vote of 5 This is so simple it makes me puke a... PinprotectorAspDotNetDev7-Apr-11 9:11 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 26 Feb 2010
Article Copyright 2010 by MarkLTX
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid