Tuesday, December 14, 2010

CAML vs LINQ

LINQ
The LINQ to SharePoint project provides a custom query provider for LINQ that allows to query SharePoint lists using familiar LINQ syntax. LINQ stands for Language Integrated Query and is one of the core features of Microsoft's .NET Framework 3.5 release. Features :
Custom query provider that translates LINQ queries to CAML, the Collaborative Application Markup Language used by SharePoint for querying.
· Support for LINQ in C# 3.0 +
· Entity creation tool SpMetal to export SharePoint list definitions to entity classes used for querying.
· Visual Studio 2008 integration for entity creation (a.k.a. SPML).
· Can connect to a SharePoint site either using the SharePoint object model or via the SharePoint web services.
· Planned support for updating through entity types.
Advantage
· Fast data Retrieval
· Can write SQL like queries
· Return xml output, thus can be used to retrieve relational (parent-child)data.
Disadvantage:
· Cannot use LINQ in client object Modal. It runs on server only.
· It’s converts the LINQ query into CAML therefore, adding an extra step from data retrieval

CAML
Collaborative Application Markup Language (CAML) is the XML-based language that is used to build and customize Web sites based on SharePoint Team Services from Microsoft.
CAML can be used to do the following:
· Provide schema definition to the Web site provisioning system about how the site looks and acts.
· Define views and forms for data and page rendering or execution.
· Act as a rendering language that performs functions in the DLL like pulling a value from a particular field.
· Provide batch functionality for posting multiple commands to the server using protocol.

CAML can be used in various ways to customize a SharePoint site, including the following:
· In script or code that implements members of the SharePoint Foundation object model, where CAML strings are passed through method parameters, assigned to properties, or returned by methods and properties
· In SOAP messaging that passes CAML strings to a SharePoint Foundation Web service to interact remotely with a deployment
· In front-end site definitions used to instantiate SharePoint sites
· In SharePoint Foundation Features to add specific functionality within a particular scope
· Advantages
· Avoids hand-editing of literal XML strings in your code.
· Eliminates query failures caused by typos and improper casing of elements and attributes.
· Each query component is processed as a separate statement with strongly-typed parameters.
· Operator and method overloading greatly simplifies the raw CAML schema.
· Enables the use of variables instead of literal text to specify query components.
· Visual Studio intelligence support while writing queries.
· Simplifies the construction of reusable CAML component libraries.
· Supports automatic data-binding to any .Net class or data structure.
CAML vs. LINQ
1. The principal advantages of CAML queries are that there may be a performance advantage because there is no need to translate the query from LINQ syntax to CAML syntax.
2. The principal advantages of using LINQ queries include:
· You can use LINQ syntax and the LINQ keywords built into C# and Microsoft Visual Basic. By contrast, CAML XML is error prone and applicable only to SharePoint Foundation.
· With the LINQ to SharePoint provider, you are working with strongly typed list item objects.

For Information please refer the following links:
http://msdn.microsoft.com/en-us/library/ms426449.aspx
http://msdn.microsoft.com/en-us/library/ee536691.aspx

No comments:

Post a Comment