170 likes | 328 Views
Welcome. SharePoint data access and LINQ to SharePoint. Blog: http://blog.sharepointsite.co.uk Twitter: @PaulBeck1 Email : paul.beck@sharepointsite.co.uk. Monday, April 04, 2011 from 6:00 PM - 8:00 PM – Johannesburg South Africa. Overview of the Evening. SharePoint Lists
E N D
Welcome SharePoint data access and LINQ to SharePoint Blog: http://blog.sharepointsite.co.uk Twitter: @PaulBeck1 Email: paul.beck@sharepointsite.co.uk Monday, April 04, 2011 from 6:00 PM - 8:00 PM – Johannesburg South Africa
Overview of the Evening • SharePoint Lists • Overview of SharePoint Data Access • LINQ to SharePoint • How to use LINQ to SharePoint (CRUD) • Demonstration
SharePoint Lists Comparison of SP2010 lists vs. DB tables
Overview of SP2010 Data Access Web Services REST APIs Client-side Strongly-typed ClientOM Weakly-typed Data Platform Farm Site List Data External Lists Server-side ServerOM Weakly-typed LINQ to SharePoint Strongly-typed New in SP2010 Adapted from Todd Bleeker
SP2010 Data Access Client Object Model • 3 options • Silverlight CLR • .NET CLR • JavaScript Client Application Using Client OM SharePoint 2010 XML context.ExecuteQuery(); ListData.svc (WCF) JSON Server OM
SP2010 Data Access REST API Syntax: /_vti_bin/ListData.svc/{Entity}[({identifier})]/[{Property}] Example to get the tax spent for the 4th Order: /_vti_bin/ListData.svc/Orders(4)/TaxSpent Web Service *.asmx
SP2010 Data Access Server Object Model • Managed code for COM • Flexible scope • List performance (CAML) • CAML to manipulate SP2010 list data • SPQuery(query within the site) • SPSiteDataQuery (cross site collection query) • U2U tool
LINQ to SharePoint LINQ to SharePoint = SPLINQ = SPMetal • LINQ syntax, lambda & strongly-typed
Decision Matrix for SP2010 Data Access Source: Todd Bleeker & Paul Schaeflein –SP data access decision matrix
Overview of SP2010 Data Access Other Options • LINQ to SQL • Entity framework • BCS • WCF/Web Services • BLOB Storage • AZURE/the cloud • File systems • XML
SPMetal.exe • SPMetal.exe is the tooling to generate the LINQ to SharePoint proxy code • Generates strongly typed classes • SPMetal.exe in 14\bin • Syntax: • spmetal /web:<url> /code:<file> • spmetal/web:<url> /code:<file> /parameters:<file> • spmetal /web:http://localhost /code:c:\ListData.cs/namespace:PaulBeck.SP2010.BOL • Use parameters file, otherwise a class will be generated for each visible list, only show id and version from the hidden fields • More flexible
Issues with LINQ to SharePoint • “Inefficient” queries – Querying data, Joins .ToList() - Non CAML compliant queries need to work around using LINQ to Objects. • Add hidden fields, hide lists (parameters file) • Only supports SP2010 foundation fields • Attachments, managed metadata, custom site columns requires ICustomMapping. • SPMetal cannot query cross site collections • External Content Types are not supported
Query across site collections • How many site collections? • Microsoft supports up to 200 GB content databases: performance decreases & disaster recovery becomes complex • Create several site collections (be prepared as LINQ to SharePoint doesn’t cross Site collections unless you use REST with LINQ to SharePoint)
LINQ to SharePoint Best Practices • ObjectTrackingEnabled=false; • Use parameters to include hidden fields • Use projected fields, lookups are expensive • ImplementICustomMapping.Resolve(..) • Use the developer dashboard
SPMetal.exe with parameters • Generated code Demonstration
Thank-you Blog: http://blog.sharepointsite.co.uk Twitter: @PaulBeck1 Email: paul.beck@sharepointsite.co.uk
References & Thanks • Paul Schaeflein • Todd C. Bleeker • Serge Luca • MostafaElzoghbi