Friday, February 11, 2011

Query enhancements in SharePoint 2010

This feature is for developers I could say. I am really impressed with some concepts in SharePoint 2010. Thanks to Microsoft.

  • Querying in Server side code
  • Querying in client side code

Querying in server side code

1. Linq to SharePoint: I believe you know already about Linq to SQL [Writing queries using object model in server code language against SQL Server]. This is same concept but we write queries which run against SharePoint data sources in Linq to SharePoint.

In earlier version, if you want to get the list or library data in SharePoint Server Object Model either you used CAML queries or object model. But, with this Linq to SharePoint model there is no need to write CAML queries explicitly. So, by using Linq to SharePoint provider you write code in server object model using Linq syntax. At run time Linq to SharePoint provider translates the Linq query to CAML query [Linq to Sql provider translates the queries to SQL format whereas Linq to SharePoint provider translates the queries to CAML format] and submits to database.  Now, we have to think how the classes available to write Linq to SharePoint query. For example, to write a query against a list you should have the list class in the project. To get the classes we have to use a tool provided by SharePoint Foundation called SPMetal.

Note: Linq syntax can be applied on any class that is inheriting from IEnumerable<T>.

2. Joins in CAML queries: Now join is supported in CAML queries. For this you have to use Join Element. And to specify what are the output fields in the result set we have to use ProjectedFields Element. Please read them before use them.

Querying in client side code

  1. Query using Client Object Model
    • Using queries in Client OM: This is as usual by using SPQuery class.
    • Using Linq to  Objects,:SharePoint objects which inherits from IEnumberable<T>. For example, after you get the collection of list items then you can query that list for some sub result set etc..
  2. ADO.NET Data Services Framework: You can directly connect to the content database of the SharePoint site and create objects and do your own stuff.
  3. Using Web Services and calling OWSSVR.DLL: This is still supported in SharePoint Foundation 2010. But, not recommended from Microsoft and team as they don’t yield best performance and usability when compared to above two methods.

No comments:

Post a Comment