farm site list data external lists clientom client om rest apis

40
Developing with REST and LINQ in SharePoint 2010 Todd C. Bleeker, PhD Chief Software Architect Mindsharp Paul Schaeflein Manager, Advanced Technologies LaSalle Consulting Partners

Upload: randall-williams

Post on 19-Jan-2016

230 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Farm Site List Data External Lists ClientOM Client OM REST APIs

Developing with REST and LINQ in SharePoint 2010

Todd C. Bleeker, PhDChief Software ArchitectMindsharp

Paul SchaefleinManager, Advanced TechnologiesLaSalle Consulting Partners

Page 2: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 3: Farm Site List Data External Lists ClientOM Client OM REST APIs

Agenda

Overview of Data TechnologiesDescribe SharePoint 2010 List Data Model EnhancementsDemo new List Data Platform capabilitiesDemo REST APIsDemo Client OMDemo LINQ to SharePoint

Page 4: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 5: Farm Site List Data External Lists ClientOM Client OM REST APIs

Data PlatformScope

Query

Lists

External Lists

File System

List Data Model

Page 6: Farm Site List Data External Lists ClientOM Client OM REST APIs

List Data ModelList Lookups

Lookups form relationships between listsOne-to-manyMany-to-many

1 m mProjects TimecardsClients

Lookup

1

Lookup

Page 7: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 8: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 9: Farm Site List Data External Lists ClientOM Client OM REST APIs

List Data ModelValidation and Uniqueness

Validation Formula can be specified onList and Columns

Example: =[Discount] < [Cost]

Column uniqueness constraint

Page 10: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 11: Farm Site List Data External Lists ClientOM Client OM REST APIs

New List Capabilities

Relationships, No Duplicates, Projection,Multi-Values Lookups, Data Integrity, Data Validation, Query Throttling

demo

Page 12: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 13: Farm Site List Data External Lists ClientOM Client OM REST APIs

Client OMUnified Clients

Unified object model across all clientsJavaScript.NET CLRSilverlight CLR

Subset of Server OMWebs, Lists, ListItems, Content Types, Fieldsetc.

Page 14: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 15: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 16: Farm Site List Data External Lists ClientOM Client OM REST APIs

Client Object Model

Accessing SharePoint Data using the JavaScript Client Object Model

demo

Page 17: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 18: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 19: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 20: Farm Site List Data External Lists ClientOM Client OM REST APIs

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'

Page 21: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 22: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 23: Farm Site List Data External Lists ClientOM Client OM REST APIs

REST APIs

Accessing SharePoint Data using the REST API from JavaScript

demo

Page 24: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 25: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 26: Farm Site List Data External Lists ClientOM Client OM REST APIs

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};

Page 27: Farm Site List Data External Lists ClientOM Client OM REST APIs

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>

Page 28: Farm Site List Data External Lists ClientOM Client OM REST APIs

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)};

Page 29: Farm Site List Data External Lists ClientOM Client OM REST APIs

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>

Page 30: Farm Site List Data External Lists ClientOM Client OM REST APIs

LINQ to SharePoint

Accessing Relational SharePoint Data using LINQ to SharePoint

demo

Page 31: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 32: Farm Site List Data External Lists ClientOM Client OM REST APIs

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)

Page 33: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 34: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 35: Farm Site List Data External Lists ClientOM Client OM REST APIs

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

Page 36: Farm Site List Data External Lists ClientOM Client OM REST APIs

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)

Page 37: Farm Site List Data External Lists ClientOM Client OM REST APIs

Learn More about SharePoint 2010

Information forIT Prosat TechNet

http://MSSharePointITPro.com

Information forDevelopers

at MSDNhttp://MSSharePointDeveloper.com

Information forEveryone

http://SharePoint.Microsoft.com

Page 38: Farm Site List Data External Lists ClientOM Client OM REST APIs

© 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.

Page 39: Farm Site List Data External Lists ClientOM Client OM REST APIs
Page 40: Farm Site List Data External Lists ClientOM Client OM REST APIs