36
Developing with REST and LINQ in Microsoft SharePoint 2010 Paul Schaeflein, MCT Manager of Advanced Technologies LaSalle Consulting Partners, Inc. SESSION CODE: OSP309

Paul Schaeflein, MCT Manager of Advanced Technologies LaSalle Consulting Partners, Inc. SESSION CODE: OSP309

Embed Size (px)

Citation preview

Developing with REST and LINQ in Microsoft SharePoint 2010 Paul Schaeflein, MCTManager of Advanced TechnologiesLaSalle Consulting Partners, Inc.

SESSION CODE: OSP309

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 CapabilitiesRelationships, No Duplicates, Projection,Multi-Values Lookups, Data Integrity, Data Validation, Query Throttling

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 WCF 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 APIsAccessing 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 provider

Sample: Original LINQ queryfrom p in data.Projects

where p.Client.City == "Chicago"

select new{ Name = p.Title, ClientName = p.Client.Title, Budget = p.BudgetHours};

LINQ to SharePoint provider

Sample: 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 provider

Sample: Original LINQ queryfrom tc in data.Timecards

where tc.Id == 4

group tc by tc.WorkDate.Value.ToString("MM/yy") into tcsselect new{ Month = tcs.Key, Total = tcs.Sum(t => t.Hours)};

LINQ to SharePoint provider

Sample: 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 SharePointAccessing Relational SharePoint Data using LINQ to SharePoint

demo

Data Technologies in SharePoint 2010

SharePoint 2010 List Data ModelRelationships, Joins, and Data Integrity

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 Matrix

Managed 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 Identity No RoleDefinitionBindingCollection Identity

SPWeb Locale for Comparisons Invariant Culture for Comparisons

Related Content

Breakout Sessions – See Conference Guide for full list of OSP Track Sessions

Interactive Sessions – OSP Track has 10 Interactive Sessions – OSP01-INT – OSP10-INT

Hands-on Labs – OSP01-HOL – OSP20-HOL

Product Demo Stations: Yellow Section, OSPOffice 2010, SharePoint 2010, Project Server 2010, Visio 2010 have kiosks & demos

Track Resources

For More Information: http://sharepoint.microsoft.com

SharePoint Developer Center: http://msdn.microsoft.com/sharepoint

SharePoint Tech Center: http://technet.microsoft.com/sharepoint

Official SharePoint Team Blog: http://blogs.msdn.com/sharepoint

Track ResourcesFor More Information – http://sharepoint.microsoft.com SharePoint Developer Center – http://msdn.microsoft.com/sharepointSharePoint Tech Center – http://technet.microsoft.com/sharepointOfficial SharePoint Team Blog – http://blogs.msdn.com/sharepoint

Related ContentBreakout Sessions – See Conference Guide for full list of OSP Track SessionsInteractive Sessions – OSP Track has 10 Interactive Sessions – OSP01-INT – OSP10-INTHands-on Labs – OSP01-HOL – OSP20-HOLProduct Demo Stations – Yellow Section, OSP

Office 2010, SharePoint 2010, Project Server 2010, Visio 2010 have kiosks and demos

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

Complete an evaluation on CommNet and enter to win!

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st

http://northamerica.msteched.com/registration

You can also register at the

North America 2011 kiosk located at registrationJoin us in Atlanta next year

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

JUNE 7-10, 2010 | NEW ORLEANS, LA