Thursday, 10 March 2011

LinqPad on SharePoint data

Linq to SharePoint is great! The SPMetal.exe is really easy to use (see here how to use it).
But I was struggling a bit to get the right Linq queries. So I thought, well let's use LinqPad. I ran into the following error message:
PropertyOrFieldNotInitializedException: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
I searched for a solution, but I didn't find one. Today I figured out how to use LinqPad to query on SharePoint data, without facing these security-IIS-related issues.
On CodePlex you can find the LinqPad Data Context Driver for SharePoint created by a guy named 'theiwaz'. Creating a new connection in LinqPad, using this driver did the trick. Read the documentation how to install and setup the configuration (very easy!).

In my situation, I ran into a small problem. The documentation shows a screenshot with a sample code, using "C# Expression" a the language.
When I tried that, it failed. I got the following message:
String was not recognized as a valid Boolean
 Changing the language to "C# Statement(s)" did the trick for me. I only need to rewrite the code a little bit. But that's actually a great advantage, because it now looks like the code as I will use inside my VS2010 project.
var q = from prod in Products
    where prod.Customer.Title == "DNM"
    select  prod.Title;



theiwaz said...

Hey Robje,

I just want to announce that there is a new release of this driver which allows "on the fly" generation of the SharePoint entities to be used with LinqPad.


Robje said...

Hey theiwaz,

Thanks for this update reminder! I will have a look soon.