Looking for something?

Author: Tobias Zimmergren
http://www.zimmergren.net | http://www.tozit.com | [@zimmergren](http://www.twitter.com/zimmergren)


The two following questions are quite popular in my SharePoint 2010 developer training classes, so I ought to answer them right here.

  1. "What does LINQ to SharePoint really do?"
  2. "Can I see the CAML query generated by the LINQ to SharePoint query?"

The answer is simple: Yes, you can see the results of your generated LINQ query by using the Log property of your DataContext object.

What CAML lied behind my LINQ to SharePoint query?

In order to fetch the CAML query that lies behind your LINQ query, all you need is to work with the .Log object of your DataContext.

See this simple example, which simply outputs the CAML query to an XML-file for easy reading:


This will essentially generate the following content in the file C:MyEntitiesDataContextQuery.xml:


As you can see, the LINQ to SharePoint query is automatically turned into a CAML Query.


Yep, all you need is the .Log property to fetch the CAML query from your LINQ statement. In my sample I’m outputting it to a file called C:MyEntitiesDataContextQuery.xml.

You could of course output it in any other way you want – not just a physical file on the file system. The Log property is of the type TextWriter.


0 Comments 19 February 2010
Tobias Zimmergren

Tobias Zimmergren

Hi, I'm Tobias. I am a Microsoft MVP for SharePoint and I use this site to share my thoughts on tech with you on topics like SharePoint, Office 365, Azure and general web development.

  Malmö, Sweden

Related Post

Comments powered by Disqus