With SharePoint 2007, we had to use CAML queries to write queries against the server, using the SPQuery or SPSiteDataQuery objects. You would write your CAML as a string and pass it to those objects, so there were no strongly typed objects or syntax checking as part of the API. Instead, you would either have to cross your fingers that you got the query right or use a third-party tool to try to generate your CAML queries. To make this easier, SharePoint 2010 introduces SharePoint LINQ (SPLINQ). By having a LINQ Provider, 2010 allows you to use LINQ to write your queries against SharePoint in a strongly typed way with Intellisense and compile-time checking. Under the covers, the SharePoint LINQ provider translates your LINQ query into a CAML query and executes it against the server. As you will, you can retrieve the CAML query that the LINQ provider generated to understand what is being passed back to the server.
Sample code in old days:
SpSite site = new SpSite(http://samlehome.com/);
SpWeb web = site.openweb();
List<SPList> hiddenLists = new List<SPlist>(); // Do not use an SPListCollection here
foreach (SPList list in web.Lists){
if (list.Hidden)
hiddenLists.Add(list);
}
Notice number of lines of code with LINQ:
SPSite site = new SPSite("http://samlehome.com");SPWeb web = site.AllWebs[0];var hiddenLists = from list in web.Lists where list.Hidden select list;
Sample code in old days:
SpSite site = new SpSite(http://samlehome.com/);
SpWeb web = site.openweb();
List<SPList> hiddenLists = new List<SPlist>(); // Do not use an SPListCollection here
foreach (SPList list in web.Lists){
if (list.Hidden)
hiddenLists.Add(list);
}
Notice number of lines of code with LINQ:
SPSite site = new SPSite("http://samlehome.com");SPWeb web = site.AllWebs[0];var hiddenLists = from list in web.Lists where list.Hidden select list;