farm site list data external lists clientom client om rest apis
TRANSCRIPT
Developing with REST and LINQ in SharePoint 2010
Todd C. Bleeker, PhDChief Software ArchitectMindsharp
Paul SchaefleinManager, Advanced TechnologiesLaSalle Consulting Partners
Session Objectives And Takeaway
Session Objectives: Explain SharePoint 2010 data technologiesShow the relative strengths of each SharePoint data access technologyPresent the new List Platform capabilitiesDemonstrate how to interact with SharePoint data using the new SharePoint APIs
TakeawayVisual Studio 2010 projects showing powerful ways to access SharePoint Data
http://SharePoint.MindsharpBlogs.com/Todd/SPC
Agenda
Overview of Data TechnologiesDescribe SharePoint 2010 List Data Model EnhancementsDemo new List Data Platform capabilitiesDemo REST APIsDemo Client OMDemo LINQ to SharePoint
Overview of Data Technologies
LINQ
Farm Site List Data External Lists
Data Platform
Client-side
Server-side
Strongly-typed
Weakly-typed
Strongly-typed
Weakly-typedServer OM
Client OM
REST APIs
New in 2010
Improved
Data PlatformScope
Query
Lists
External Lists
File System
List Data Model
List Data ModelList Lookups
Lookups form relationships between listsOne-to-manyMany-to-many
1 m mProjects TimecardsClients
Lookup
1
Lookup
List Data ModelLists Relationships and Data Integrity
One-to-many relationships can be used to:Trigger Cascade DeleteRestrict Delete
1 m m
Lookup
1
Lookup
ProjectsClients Timecards
List Data ModelLists Joins and Projections
Query within and across lists:Join lists using lookup columnsLookup to multiple columns
1 m m
Lookup
1
Lookup
QueryResult Set
ProjectsClients Timecards
List Data ModelValidation and Uniqueness
Validation Formula can be specified onList and Columns
Example: =[Discount] < [Cost]
Column uniqueness constraint
List Data ModelAutomatic large query throttling
Check query before executionIf Index is not used and number of scanned rows is greater than a limit then block queryIf 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
Relationships, No Duplicates, Projection,Multi-Values Lookups, Data Integrity, Data Validation, Query Throttling
demo
Next: Client Object Model (OM)
LINQ
Farm Site List Data External Lists
Data Platform
Client-side
Server-side
Strongly-typed
Weakly-typed
Strongly-typed
Weakly-typedServer OM
Client OM
REST APIs
New in 2010
Improved
Client OMUnified Clients
Unified object model across all clientsJavaScript.NET CLRSilverlight CLR
Subset of Server OMWebs, Lists, ListItems, Content Types, Fieldsetc.
Client OMGenerally How It Works
XML
JSON
Execute commandsin the batch:
Client.svcSequence of commands:
context.ExecuteQuery();
command 1;command 2;command 3;
Send results back
command 1;command 2;command 3;
Process results
ServerClient Application
Using the Client OM
Server OM
Managed OM
ManagedControls
ManagedLogic
Proxy XML
JavaScriptControls
JavaScriptLogic
JavaScript OM
Proxy XML
Client.svcWeb Browser
Managed Client SharePoint Server
ContentDatabase
JSON response
XmlHttpRequest.post
HttpWebRequest.post
JSON response
Client Object Model
Accessing SharePoint Data using the JavaScript Client Object Model
demo
Next: REST APIs
LINQ
Farm Site List Data External Lists
Data Platform
Client-side
Server-side
Strongly-typed lists
Weakly-typed lists
Strongly-typed lists
Weakly-typed listsServer OM
Client OM
REST APIs
New in 2010
Improved
REST APIsREST-style ListData.svc Web Service
Work with data viaRepresentational State Transfer (REST)
SharePoint list dataOther data sources as well
Excel spreadsheetsAzure cloud store
Powered by ADO.NET Data Services “Astoria”REST Protocols: Atom, AtomPub, and JSONIntegration 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 APIs QueryString 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
Accessing SharePoint Data using the REST API from JavaScript
demo
Next: LINQ to SharePoint provider
LINQ
Farm Site List Data External Lists
Data Platform
Client-side
Server-side
Strongly-typed lists
Weakly-typed lists
Strongly-typed lists
Weakly-typed listsServer OM
Client OM
REST APIs
New in 2010
Improved
LINQ to SharePointStrongly-typed access to List Data on Server
Entity based programming on the serverSPMetal Code Generation UtilityLINQ QueriesStrong Types
Translates LINQ queries into CAML queries
Can be used inWeb Parts, Event Receivers, Sandboxed code
LINQ to SharePoint providerSample: Original LINQ query
from p in data.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> <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x0100</Value> </BeginsWith> <Eq> <FieldRef Name="ClientCity" /> <Value Type="Lookup">Chicago</Value> </Eq> </And> </Where></Query>
<ViewFields> <FieldRef Name="Title" /> <FieldRef Name="ClientTitle" /> <FieldRef Name="BudgetHours" /></ViewFields>
<ProjectedFields> <Field Name="ClientTitle" Type="Lookup" List="Client" ShowField="Title" /> <Field Name="ClientCity" Type="Lookup" List="Client" ShowField="City" /></ProjectedFields>
<Joins> <Join Type="LEFT" ListAlias="Client"> <!--List Name: Clients--> <Eq> <FieldRef Name="Client" RefType="ID" /> <FieldRef List="Client" Name="ID" /> </Eq> </Join></Joins>
LINQ to SharePoint providerSample: Original LINQ query
from tc in data.Timecardswhere tc.Id == 4group tc by tc.WorkDate.Value.ToString("MM/yy") into tcsselect new{ Month = tcs.Key, Total = tcs.Sum(t => t.Hours)};
LINQ to SharePoint providerSample: Generated CAML Query
<Query> <Where> <And> <BeginsWith> <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x0100</Value> </BeginsWith> <Eq> <FieldRef Name="ID" /> <Value Type="Counter">4</Value> </Eq> </And> </Where></Query> <ViewFields>
<FieldRef Name="StaffId" /> <FieldRef Name="WorkDate" /> <FieldRef Name="Hours" /> <FieldRef Name="Project" /> <FieldRef Name="ID" /> <FieldRef Name="owshiddenversion" /> <FieldRef Name="Title" /> </ViewFields> <RowLimit Paged="TRUE">2147483647</RowLimit>
LINQ to SharePoint
Accessing Relational SharePoint Data using LINQ to SharePoint
demo
Data Technologies in SharePoint 2010
SharePoint 2010 List Data ModelRelationships, Joins, and Data Integrity
Client OM and Server OMComplete set of data APIs on both server and client side
REST APIs and LINQ to SharePointSimple and integrated developer experience for list based Data Applications
Data Access TechnologiesDecision Matrix
Client OM Server OM REST LINQ to SharePoint
On SharePoint Server
On Remote Computer
Site / List Objects
Traverse Relationships
Calling Pattern (Direct)
Calling Pattern (Callback)
Strongly-Typed(Columns as Properties)
Data Access TechnologiesDecision MatrixManaged Client OMs JavaScript Client OM
Full URL Context Server-relative Context Only
StringCollection string[] Array
Null, infinity Nan, positive/negative infinity
Explicit FBA support Context FBA support
Create, Update, Commit Create, Commit, Update
No FormDigest Required Needs <SharePoint:FormDigest>
Standard Server OM IdentityNo RoleDefinitionBindingCollection Identity
SPWeb Locale for Comparisons Invariant Culture for Comparisons
Related Content at SPC 2009
Talk Speaker
Overview of the SharePoint 2010 Developer Platform, Paul Andrew 19th 1:15 PM
Visual Studio 2010 SharePoint Development Tools Overview, Mike Morton 19th 2:45 PM
Developing SharePoint 2010 Applications with the Client Object Model, Paul Stubbs 20th 1:15 PM
SharePoint 2010 Development Best Practices, Kirk Evans 20th 4:30 PM
The New SharePoint 2010 RESTful Data Service Interface, Pablo Castro 22nd 10:30 AM
Hand on Labs Code
Developing with LINQ to SharePoint in Visual Studio 2010 SPCHOL302
Developing for SharePoint 2010 with the Client OM and REST in Visual Studio 2010 SPCHOL303
QuestionsSharePoint kiosk:
In the Microsoft PavilionImmediately following session
Ask the Experts:Wednesday Evening5:45pm – 7:30pm in the Exhibit Hall
Online:http://sharepoint.mindsharpblogs.com/todd http://sharepoint.mindsharpblogs.com/paul
Remember to fill out your evaluations on MySPC
for 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 forDevelopers
at MSDNhttp://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.