Friday, July 27, 2012

LINQ to SharePoint

Why use LINQ instead of CAML

  • Intellisense
  • Compile-time type checking
  • You don’t have to know CAML which is not as well documented.
  • If you know LINQ to ??? you already have a good feel for the syntax.

Supported Environments

From what I can tell (I found conflicting information on this and I could not get it to work) you can’t use spmetal (which is required for LINQ to SharePoint) on SharePoint Online. However, if you are using SharePoint 2010 (on premise) it does generate ok, so I expect the LINQ to SharePoint would work as expected.

Learn more about LINQ to SharePoint

  1. Introducing Linq to SharePoint Video – Good place to start.
  2. LINQ Syntax Video – Learn the basics of the syntax for general LINQ (if you don’t know it already)
  3. Accessing SharePoint Data using LINQ to SharePoint

Basics

  1. Create Entity Classes using SPMetal
  2. Add reference to Microsoft.SharePoint.Linq.dll to your project
  3. Create DataContext
  4. Write Queries

No comments: