400 likes | 718 Views
Developing with REST and LINQ in SharePoint 2010. Paul Schaeflein Manager, Advanced Technologies LaSalle Consulting Partners. Todd C. Bleeker, PhD Chief Software Architect Mindsharp. Session Objectives And Takeaway. Session Objectives: Explain SharePoint 2010 data technologies
E N D
Developing with REST and LINQ in SharePoint 2010 Paul Schaeflein Manager, Advanced Technologies LaSalle Consulting Partners Todd C. Bleeker, PhD Chief Software Architect Mindsharp
Session Objectives And Takeaway • Session Objectives: • Explain SharePoint 2010 data technologies • Show the relative strengths of each SharePoint data access technology • Present the new List Platform capabilities • Demonstrate how to interact with SharePoint data using the new SharePoint APIs • Takeaway • Visual Studio 2010 projects showing powerful ways to access SharePoint Data http://SharePoint.MindsharpBlogs.com/Todd/SPC
Agenda • Overview of Data Technologies • Describe SharePoint 2010 List Data Model Enhancements • Demo new List Data Platform capabilities • Demo REST APIs • Demo Client OM • Demo LINQ to SharePoint
Overview of Data Technologies REST APIs Strongly-typed ClientOM Weakly-typed Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed LINQ Strongly-typed New in 2010 Improved
Data PlatformScope List Data Model File System Lists Query External Lists
List Data ModelList Lookups • Lookups form relationships between lists • One-to-many • Many-to-many Lookup Lookup 1 1 m m Clients Projects Timecards
List Data ModelLists Relationships and Data Integrity • One-to-many relationships can be used to: • Trigger Cascade Delete • Restrict Delete Lookup Lookup 1 1 m m Clients Projects Timecards
List Data ModelLists Joins and Projections • Query within and across lists: • Join lists using lookup columns • Lookup to multiple columns Lookup Lookup 1 1 m m Clients Projects Timecards Query Result Set
List Data ModelValidation and Uniqueness • Validation Formula can be specified on List and Columns Example: =[Discount] < [Cost] • Column uniqueness constraint
List Data ModelAutomatic large query throttling • Check query before execution • If Index is not used and number of scanned rows is greater than a limit then block query • If number of Joins is greater than limit then block query • If enabled on the Web Application, the developer can turn off throttling using:SPQuery.RequestThrottleOverride and SPSiteDataQuery.RequestThrottleOverride
New List Capabilities demo Relationships, No Duplicates, Projection,Multi-Values Lookups, Data Integrity, Data Validation, Query Throttling
Next: Client Object Model (OM) REST APIs Strongly-typed Client OM Weakly-typed Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed LINQ Strongly-typed New in 2010 Improved
Client OMUnified Clients • Unified object model across all clients • JavaScript • .NET CLR • Silverlight CLR • Subset of Server OM • Webs, Lists, ListItems, • Content Types, Fields • etc.
Client OMGenerally How It Works Client Application Server Sequence of commands: Client.svc command 1; command 2; command 3; Execute commands in the batch: XML command 1; command 2; command 3; context.ExecuteQuery(); JSON Process results Send results back
Using the Client OM JavaScript Logic JavaScript Controls JavaScript OM JSON response XmlHttpRequest.post Proxy XML Client.svc Server OM Web Browser HttpWebRequest.post Proxy XML JSON response Managed OM Content Database Managed Controls Managed Logic SharePoint Server Managed Client
Client Object Model demo Accessing SharePoint Data using the JavaScript Client Object Model
Next: REST APIs REST APIs Strongly-typed lists ClientOM Weakly-typed lists Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed lists LINQ Strongly-typed lists New in 2010 Improved
REST APIsREST-style ListData.svc Web Service • Work with data viaRepresentational State Transfer (REST) • SharePoint list data • Other data sources as well • Excel spreadsheets • Azure cloud store • Powered by ADO.NET Data Services “Astoria” • REST Protocols: Atom, AtomPub, and JSON • Integration and Standardization
REST APIsURI Map - Entity Properties • Syntax: • /_vti_bin/ListData.svc/{Entity}[({identifier})]/[{Property}] • Example to get budget hours for Project #4: • /_vit_bin/ListData.svc/Projects(4)/BudgetHours
REST APIsURI Map Filter • Syntax: • /_vti_bin/ListData.svc/{Entity}?$filter={simple predicate} • Example to get Projects for Clients in Chicago: • /_vit_bin/ListData.svc/Projects?$filter=Client/City eq 'Chicago'
REST APIsURI Map – Expand (think Join) • Syntax: • /_vti_bin/ListData.svc/{Entity}?$expand={Entity} • Example to get a Project and its related Client: • /_vit_bin/ListData.svc/Projects?$expand=Client
REST APIsQueryString Parameters • $filter={simple predicate} • $expand={Entity} • $orderby={property} • $skip=n • $top=n • $metadata • See: http://msdn.microsoft.com/en-us/library/cc907912.aspx
REST APIs demo Accessing SharePoint Data using the REST API from JavaScript
Next: LINQ to SharePoint provider REST APIs Strongly-typed lists ClientOM Weakly-typed lists Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed lists LINQ Strongly-typed lists New in 2010 Improved
LINQ to SharePointStrongly-typed access to List Data on Server • Entity based programming on the server • SPMetal Code Generation Utility • LINQ Queries • Strong Types • Translates LINQ queries into CAML queries • Can be used in • Web Parts, Event Receivers, Sandboxed code
LINQ to SharePoint providerSample: Original LINQ query • from p indata.Projectswhere • p.Client.City == "Chicago"select new • { • Name = p.Title, • ClientName = p.Client.Title, • Budget = p.BudgetHours • };
LINQ to SharePoint providerSample: Generated CAML Query • <Query> • <Where> • <And> • <BeginsWith> • <FieldRefName="ContentTypeId" /> • <ValueType="ContentTypeId">0x0100</Value> • </BeginsWith> • <Eq> • <FieldRefName="ClientCity" /> • <ValueType="Lookup">Chicago</Value> • </Eq> • </And> • </Where> • </Query> • <ViewFields> • <FieldRefName="Title" /> • <FieldRefName="ClientTitle" /> • <FieldRefName="BudgetHours" /> • </ViewFields> • <ProjectedFields> • <FieldName="ClientTitle" Type="Lookup" • List="Client" ShowField="Title" /> • <FieldName="ClientCity" Type="Lookup" • List="Client" ShowField="City" /> • </ProjectedFields> • <Joins> • <JoinType="LEFT" ListAlias="Client"> • <!--List Name: Clients--> • <Eq> • <FieldRefName="Client" RefType="ID" /> • <FieldRefList="Client" Name="ID" /> • </Eq> • </Join> • </Joins>
LINQ to SharePoint providerSample: Original LINQ query • fromtcindata.Timecardswhere • tc.Id == 4group tcby tc.WorkDate.Value.ToString("MM/yy") into tcs • select new • { • Month = tcs.Key, • Total = tcs.Sum(t => t.Hours) • };
LINQ to SharePoint providerSample: Generated CAML Query • <Query> • <Where> • <And> • <BeginsWith> • <FieldRefName="ContentTypeId" /> • <ValueType="ContentTypeId">0x0100</Value> • </BeginsWith> • <Eq> • <FieldRefName="ID" /> • <ValueType="Counter">4</Value> • </Eq> • </And> • </Where> • </Query> • <ViewFields> • <FieldRefName="StaffId" /> • <FieldRefName="WorkDate" /> • <FieldRefName="Hours" /> • <FieldRefName="Project" /> • <FieldRefName="ID" /> • <FieldRefName="owshiddenversion" /> • <FieldRefName="Title" /> • </ViewFields> • <RowLimitPaged="TRUE">2147483647</RowLimit>
LINQ to SharePoint demo Accessing Relational SharePoint Data using LINQ to SharePoint
Data Technologies in SharePoint 2010 • SharePoint 2010 List Data Model • Relationships, Joins, and Data Integrity • Client OM and Server OM • Complete set of data APIs on both server and client side • REST APIs and LINQ to SharePoint • Simple and integrated developer experience for list based Data Applications
Questions • SharePoint kiosk: • In the Microsoft Pavilion • Immediately following session • Ask the Experts: • Wednesday Evening • 5:45pm – 7:30pm in the Exhibit Hall • Online: • http://sharepoint.mindsharpblogs.com/todd • http://sharepoint.mindsharpblogs.com/paul
Remember to fill out your evaluations onMySPCfor your chance to win two HD web cams and a designer mouse (3 prizes awarded daily)
Learn More about SharePoint 2010 Information forIT Prosat TechNet http://MSSharePointITPro.com Information forDevelopersat MSDN http://MSSharePointDeveloper.com Information forEveryone • http://SharePoint.Microsoft.com
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.