Logging your Sql with LINQ Update Commands. Simple Logging to your Visual Studio 2008 Debugger Output Console

So, you want to do an update but are wondering what the hec LINQ is doing.  Turns out it is really easy.  All you have to do is run in the debugger and add the Log option to your data context.

Here is an example:

DataClassesGeneralDataContext db3pLogicContext;
db3pLogicContext.Log = Console.Out;
var companyQuery = from tbl in db3pLogicContext.Companies
                   where tbl.ParentId != 0
                   select tbl;
int totalCntParents = companyQuery.Count();
foreach (DBAccess.Company co in companyQuery)
    co.CreateDate = DateTime.Now;

Now, when you run the code, you can look on your debugger output and see something that looks like this:


Also, if you want to actually execute select type statements, take a look at the Query Visualizer posted on Scott Guthrie’s web site:


About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP since 2007. In addition, he’s a multi-course video author at Pluralsight. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


Get every new post delivered to your Inbox

Join other followers: