Click here to Skip to main content
11,481,265 members (64,725 online)
Click here to Skip to main content

Tagged as

See the SQL Generated by LINQ

, 26 Feb 2010 CPOL 38.8K 33
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 Pin
fakeer muhammed10-Feb-13 5:39
memberfakeer muhammed10-Feb-13 5:39 
GeneralMy vote of 5 Pin
Carsten V2.021-Jun-12 9:57
memberCarsten V2.021-Jun-12 9:57 
GeneralReason for my vote of 5 Straight to the point and provides a... Pin
BrianBissell26-Jul-11 5:28
memberBrianBissell26-Jul-11 5:28 
Reason for my vote of 5
Straight to the point and provides alternatives...awesome.
GeneralReason for my vote of 5 Very simple and effective. Pin
Pravin Patil, Mumbai19-Jul-11 0:57
memberPravin Patil, Mumbai19-Jul-11 0:57 
Generalnice and easy. Great! Pin
Member 414818817-Apr-11 20:39
memberMember 414818817-Apr-11 20:39 
GeneralReason for my vote of 5 Good to know Pin
Alomgir Miah A12-Apr-11 9:55
memberAlomgir Miah A12-Apr-11 9:55 
GeneralIs there anything like this for Entity Framework? Pin
Igor Merabishvili11-Apr-11 22:36
memberIgor Merabishvili11-Apr-11 22:36 
GeneralReason for my vote of 5 Thank you for the simple solution wh... Pin
linuxjr7-Apr-11 18:30
memberlinuxjr7-Apr-11 18:30 
GeneralReason for my vote of 5 This is so simple it makes me puke a... Pin
AspDotNetDev7-Apr-11 9:11
protectorAspDotNetDev7-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
Web04 | 2.8.150520.1 | Last Updated 26 Feb 2010
Article Copyright 2010 by MarkLTX
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid