hilton giesenow - the moss show developing with linq, rest & the new client om in microsoft...

46

Upload: edgar-sonn

Post on 28-Mar-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322
Page 2: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

Hilton Giesenow- The MOSS Show

Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010

SESSION CODE: OFC322

Page 3: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

3

Agenda

Accessing SharePoint data – then & nowList data model improvements in 2010LINQ To SharePointClient Object ModelREST

Special thanks to…

Page 4: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

4

Accessing SharePoint Data – circa 2007

Server Object ModelWeakly typedLots of XMLLong-windedNon-standardNon-relationalGarbage collection

Web ServicesWeakly typedTONS of XMLLong-windedNon-standardNon-relationalNo WCFNon standards-compliantNo flexibility

Page 5: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

5

Overview of Data Technologies

LINQ

Data Platform

Farm Site List Data External Lists

Client-side

Server-side

Strongly-typed

Weakly-typed

Strongly-typed

Weakly-typedServer OM

Client OM

REST APIs

New in 2010Improved

Web

Web Services Weakly-typed

Page 6: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

6

1 m m1

The Case Study - List Lookups

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

Restrict / Cascade Deletes

TimecardsClients Projects

Lookup Lookup

Page 7: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

7

1 m m1

List Data Model - Lists Joins and Projections

Query within and across lists:Join lists using lookup columnsLookup to multiple columns

QueryResult Set

TimecardsClients Projects

Lookup Lookup

Page 8: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

8

Take Note: List Validation and Uniqueness

Excel-like validation formulaCan be specified on Columns and Lists

Example: =[Discount] < [Cost]

Column uniqueness constraint

Page 9: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

9

Take Note: Query Throttling

Check query before executionNo index and count > limitJoins > limit

Can turn throttling off usingSPQuery.RequestThrottleOverrideSPSiteDataQuery.RequestThrottleOverride

Page 10: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

10

New List CapabilitiesRelationshipsMulti-Value LookupsData Integrity & Data ValidationQuery Throttling

Page 11: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

11

Querying SharePoint, circa 2007<Query> <Where> <Or> <Geq> <FieldRef Name=“Field1" /> <Value Type=“Number">1500</Value> </Geq> <Leq> <FieldRef Name=“Field2" /> <Value Type=“Number">500</Value> </Leq> </Or> </Where></Query>

Page 12: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

12

And the Code to Get There…SPQuery query = new SPQuery();StringBuilder sbQuery = new StringBuilder();sbQuery.Append("<where>");sbQuery.Append("<geq>");sbQuery.Append("<fieldref name=\"" + fieldName1 + "\"/>");sbQuery.Append("<value type=\"" + fieldType1 + "\">" + field Value1 + "</value>");sbQuery.Append("</geq>");sbQuery.Append("</where>");query.Query = sbQuery.ToString();

Page 13: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

13

Joins in CAML<Query> <Where> <And> <BeginsWith> <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x0100</Value> </BeginsWith> <Eq> <FieldRef Name="ClientCity" /> <Value Type="Lookup">Durban</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"> <Eq> <FieldRef Name="Client" RefType="ID" /> <FieldRef List="Client" Name="ID" /> </Eq> </Join></Joins>

Page 14: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

14

And the Code to Get There…using (SPSite site = new SPSite(SPContext.Current.Site)){ SPWeb web = site.RootWeb; if (web != null) {  SPList list = web.Lists["Parents"];  if (list != null)  {   SPQuery query = new SPQuery();   StringBuilder sbQuery = new StringBuilder();   sbQuery.Append("<where><eq>");   sbQuery.Append("<fieldref name="\"OtherChildren\"">");   sbQuery.Append("<value type="\"LookupMulti\"">My Other Child</value>");   sbQuery.Append("</fieldref></eq>");   query.Query = sbQuery.ToString();    StringBuilder sbJoins = new StringBuilder();   sbJoins.Append("<join listalias="\"OtherChildren\"" type="\"LEFT\"">");   sbJoins.Append("<eq>");   sbJoins.Append("<fieldref name="\"OtherChildren\"" reftype="\"ID\"">");   sbJoins.Append("<fieldref list="\"OtherChildren\"" name="\"ID\"">");   sbJoins.Append("</fieldref> ");   sbJoins.Append("</fieldref> ");   query.Joins = sbJoins.ToString();    StringBuilder sbProj = new StringBuilder();   sbProj.Append("<field list="\"OtherChildren\"" name="\"OtherChildrenNickname\"" showfield="\"Nickname\"" type="\"Lookup\"">");   query.ProjectedFields = sbProj.ToString();    StringBuilder sbView = new StringBuilder();   sbView.Append("<fieldref name="\"Title\"">");   sbView.Append("<fieldref name="\"OtherChildrenNickname\"">");   query.ViewFields = sbView.ToString();    if (!string.IsNullOrEmpty(query.Query))   {    SPListItemCollection matches = list.GetItems(query);    foreach (SPListItem match in matches)    {     Console.WriteLine(match["Title"]);      string rawNickname = (string)match["OtherChildrenNickname"];     if (!string.IsNullOrEmpty(rawNickname))     {      SPFieldLookupValue nickname = new SPFieldLookupValue(rawNickname);      Console.WriteLine(nickname.LookupValue);     }    }   }  } }}

Page 15: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

15

Overview of Data Technologies

LINQ

Data Platform

Farm Site List Data External Lists

Client-side

Server-side

Strongly-typed

Weakly-typed

Strongly-typed

Weakly-typedServer OM

Client OM

REST APIs

New in 2010Improved

Web

Web Services Weakly-typed

Page 16: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

16

LINQ

var CommonWords = from w in wordOccurances where w.Count > 2 select new { f.Name, w.Word, W.Count };

var CommonWords = wordOccurances .Where(w => w.Count > 2) .Select(w => new {f.Name, w.Word, W.Count });

Extension methods

Lambda expressions

Query expressions

Object initializers

Anonymous types

Local variable type inference

Page 17: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

17

Expression Trees

LinQ to…

LinQ“runtime”

Page 18: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

18

Objects

<book> <title/> <author/> <year/> <price/></book>

XML

.NET Language Integrated Query

C# 3.0 VB 9.0 Others…

Relational

LINQ toObjects

LINQ toSQL

LINQ toXML

LINQ toEntities

LINQ Architecture

LINQ toSharePoint

SharePoint (CAML)

Page 19: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

19

LINQ to SQLfrom p in dataContext.Projectswhere p.Client.City == “Durban"select new { Name = p.Title, ClientName = p.Client.Title, Budget = p.BudgetHours };

Page 20: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

20

LINQ to SQL – It's Just SQL UnderneathSELECT

[t0].[Title] AS [Name],[t1].[Title] AS [ClientName],[t0].[BudgetHours] AS [Budget]

FROM[dbo].[Projects] AS [t0]INNER JOIN [dbo].[Clients] AS [t1] ON[t1].[ID] = [t0].[ClientID]

WHERE[t1].[City] = 'Durban'

Page 21: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

21

LINQ to SharePointfrom p in dataContext.Projectswhere p.Client.City == “Durban"select new { Name = p.Title, ClientName = p.Client.Title, Budget = p.BudgetHours };

Page 22: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

22

LINQ to SharePoint – It's Just CAML Underneath<Query> <Where> <And> <BeginsWith> <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x0100</Value> </BeginsWith> <Eq> <FieldRef Name="ClientCity" /> <Value Type="Lookup">Durban</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 23: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

23

LINQ to SharePoint

demo

Accessing Relational SharePoint Data using LINQ to SharePoint

Page 24: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

24

LINQ to SharePoint – Some Limitations

Unsupported Queries & LimitsE.g. unsupported JOINSJoin Limits - MS recommends < 8Query Throttling

2-stage queriesE.g. Aggregate, Distinct, Max, Min, Sum, SkipWhile

Cross-site-collectionsAnonymous users

Page 25: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

25

Overview / Summary

SQL MetalStrong TypingRelationshipsDeferred Execution (& client-side queries)Some limitations

Page 26: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

26

Overview of Data Technologies

LINQ

Data Platform

Farm Site List Data External Lists

Client-side

Server-side

Strongly-typed

Weakly-typed

Strongly-typed

Weakly-typedServer OM

Client OM

REST APIs

New in 2010Improved

Web

Web Services Weakly-typed

Page 27: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

27

Client OMServer Side

SharePoint

Server OM

SharePoint Web services

End ClientWin

SL

JS

Client OM

Page 28: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

28

Client OM

demo

Accessing SharePoint Data using the Client OM

Page 29: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

29

Overview / Summary

Much easier than before (asmx only)asmx web services still there if we need them

Not limited to defined APISupports 3 client types

Managed Clients (sync)Silverlight (async)Javascript (async)

Page 30: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

30

Overview of Data Technologies

LINQ

Data Platform

Farm Site List Data External Lists

Client-side

Server-side

Strongly-typed

Weakly-typed

Strongly-typed

Weakly-typedServer OM

Client OM

REST APIs

New in 2010Improved

Web

Web Services Weakly-typed

Page 31: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

31

SOAP Vs. RESTi.e. What’s Wrong With SOAP?

The EnvelopeBloatedNot actually 100% interoperableNOT fun from, e.g., Javascript

The RPC-styleNeed to define entire interface

operations, params, return typesLeads to inconsistencies over timeDocumentation

Page 32: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

32

REST APIs

WCF is now supported!

What is Representational State Transfer (REST)?And what is “OData”?

Strongly typed (depending on tools...)

WCF Data Services “Astoria”

Page 33: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

33

REST Basics

Page 34: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

34

REST (OData) APIs

Syntax: /_vti_bin/ListData.svc/{Entity}[({identifier})]/[{Property}]

Example to get budget hours for Project #4: /_vit_bin/ListData.svc/Projects(4)/BudgetHours

Page 35: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

35

REST (OData) APIs

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 ‘Durban'

Page 36: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

36

REST (OData) APIs

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 37: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

37

REST (OData) APIs

$filter={simple predicate}$expand={Entity}$orderby={property}$skip=n$top=n$metadata

See: http://msdn.microsoft.com/en-us/library/cc907912.aspx

Page 38: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

38

Using the SharePoint REST (OData) APIs

demo

Page 39: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

39

Overview / Summary

Much easier than before (asmx only)asmx web services still there if we need them

Not limited to defined APISupports all client typesStrongly TypedMore ToolingOpen standards-based

Page 40: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

40

Data Technologies in SharePoint 2010

SharePoint 2010 List Data ModelRelationships, Joins, and Data Integrity

LINQ to SharePoint, Client OMSimple and integrated developer experience for list based Data Applications

WCF & REST (OData) APIsSimplified and standardized model for when you need it

Page 41: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

41

Data Access Technologies - Decision MatrixClient OM REST /

ODATAServer OM 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 42: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

42

Resources

The Moss Show - http://www.TheMossShow.com 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

Page 43: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

43

(WTB305) Panel Discussion: Ask the experts about SharePoint

(OFC423) Developing a BCS External Content Type with Visual Studio 2010

Related Content

Page 44: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

44

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

SMS [ Your Name ] and the word “Office” to 41491Need more Information?

Page 45: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

Complete an evaluation via CommNet and Tag to win amazing prizes!

Page 46: Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322

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