Pages

Thursday 9 April 2015

Comparison of CAML and LINQ in SharePoint 2010


Comparison of CAML and LINQ in SharePoint 2010

Disadvantages of CAML:
  • CAML query is text based so, if we are joining two lists across a lookup field there may be various problems associated with that.
  • CAML offers no compile time validation for the queries as queries are just
    strings that are used with objects like SPQuery, which means that during
    compile your query will never be checked for syntax errors. Furthermore, if
    your syntax is not correct you won’t get an error during runtime, the query
    just won’t return any items. That makes it extremely hard to analyze issues
    caused by faulty CAML-based queries.
  • There is no mechanism to know until run time if the query is written correctly or not. If the query is not correct, then it will simply fail at run time. Means it won’t support at design time
  • When writing the query, you have no idea what CAML elements are legal in the syntax without having a reference open.
  • The query is somewhat difficult to understand. We cannot determine easily what the query is doing and what lists are being joined.
  • The data returned from the query is placed in a SPListItem collection, which does not provide strongly typed business entities.
 Advantages of LINQ over CAML:
  • First advantage is, it is an object-oriented query language.
  • Linq stands for Linera Integrated Query. LINQ adds syntax of type SQL and vocabulary, which is used to query the data from data source. LINQ to sharepoint is defined inMicrosoft.SharePoint.Linq namespace. It translates the LINQ query into CAML (Collaborative Markup Language).
  • It can provide strongly typed objects at design time; we can create queries in code and can check that they are correct because we can the compiles the code.
  • The results are returned from queries are strongly typed objects, so the items and fields can provide compile-time checking.

Disadvantages of Using LINQ
  • ·          LINQ translates the LINQ queries into Collaborative Application Markup Language (CAML) queries thus adding an extra step for retrieving the items.
  • ow some of you may think that how CAML or LINQ queries are able to fetch the data from a list. So, below steps will clear your confusion about CAML and LINQ queries:
    • LINQ queries are converted to CAML queries.
    • CAML queries are also translated into SQL queries.

No comments:

Post a Comment