locked
LINQ in SharePoint to write CAML queries? RRS feed

  • Question

  • Will LINQ in SharePoint resolve the problem of complexity in writing CAML Queries and make it understandable for SharePoint Developers? Can anyone share their views on this.
    Tuesday, June 5, 2012 1:12 PM

Answers

  • Introduction to LINQ query is like a wrapper to the CAML query in SharePoint.

    Yes, from developers' perspective it resolves a lot of complexities in writing the CAML queries because it is easy to visualize things with LINQ as compared to CAML. CAML queries perform faster as the LINQ queries internally converted to CAML query.

    The following links can get you some better understandings.

    http://sharesilver.wordpress.com/2011/08/05/advantages-and-disadvantages-of-linq-to-sharepoint-over-caml-queries/

    http://ranaictiu-technicalblog.blogspot.in/2011/01/u2u-caml-query-builder-for-sharepoint.html


    Thanks, Suman

    • Marked as answer by GuYuming Friday, June 15, 2012 8:53 AM
    Tuesday, June 5, 2012 1:31 PM

All replies

  • Introduction to LINQ query is like a wrapper to the CAML query in SharePoint.

    Yes, from developers' perspective it resolves a lot of complexities in writing the CAML queries because it is easy to visualize things with LINQ as compared to CAML. CAML queries perform faster as the LINQ queries internally converted to CAML query.

    The following links can get you some better understandings.

    http://sharesilver.wordpress.com/2011/08/05/advantages-and-disadvantages-of-linq-to-sharepoint-over-caml-queries/

    http://ranaictiu-technicalblog.blogspot.in/2011/01/u2u-caml-query-builder-for-sharepoint.html


    Thanks, Suman

    • Marked as answer by GuYuming Friday, June 15, 2012 8:53 AM
    Tuesday, June 5, 2012 1:31 PM
  • I think this will help you.

    CAML and SPQuery

    Advantages:

    Native query syntax used by the SharePoint platform to access data held within content databases

    Fairly simple and easy to generate queries

    Disadvantages:

    Not parsed by the compiler at compile time so no validation - errors only detected at runtime

    Hard and time consuming to debug/troubleshoot

    Extensive use of indexed properties to access data - invalid index value or keys not detected at compile time

    LINQ to SharePoint

    Advantages:

    Provides a strongly typed data access layer

    Strongly typed entity objects contain the SharePoint data

    (SQL-like) LINQ syntax to perform queries

    Full design-time validation and IntelliSense support in Visual Studio 2010

    Disadvantages:

    Code is converted to CAML under the hood resulting in a slight performance hit
    Wednesday, June 6, 2012 6:50 AM
  • In our experience LINQ to SharePoint has worked much better than CAML. The saying goes human time is more expensive than server time. The speed difference between the two is not years :)

    From development/maintenance LINQ is easier. We also had a case where a portal was developed using LINQ to SP, but after a few months of use, it was decided to move data to a SQL database to increase performence, almost no code had to change, could just about swap LINQ to SP DataContext with LINQ to SQL. 

    Regards

    Wednesday, June 6, 2012 7:06 AM