Wow! LINQ to SharePoint 2010 is awesome! You have to work with it to see how it simplifies development tasks. I especially love the ability to see what underlying CAML that’s generated on the fly and passed to the server for execution. With LINQ to SharePoint, I believe, we need to have our business logic in place and know how to design “efficient queries” to get our job done! No more worries about missing a “ or confusion as to whether it’s ‘ or “ and so on…
So, I worked on a simple scenario very recently. And I used LINQ to SharePoint to achieve that task. The scenario is I have 2 lists. One of those list looks up the other list along with a few “project fields” (new in SharePoint 2010). I had to write a sample to extract data from these joined lists and to add new items to the list that looks up the other list. Confusing?? Well, read the above again and it might be clearer 🙂
This is my “Courses” list
This is my “Students” list
The students list uses the course title from courses list and also uses duration & credit points as projected fields. A quick screenshot on how to setup projected fields below.
First step is to generate the entity class file for the site using SPMetal.exe (should be located at: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN).
Add it to the VS2010 project and below is the code that helps achieving this task.
The output of this code below:
Notice the CAML dump which fires in the background. Obviously, we can appreciate the power of LINQ to SharePoint 2010 after seeing the huge CAML block that we’ll need to otherwise construct and do this simple task. I personally feel LINQ to SharePoint 2010 will be highly leveraged by developers because of its ease of use and enhanced developer productivity. Hope this post was useful and stay tuned for more.