Date post: | 28-Mar-2015 |
Category: |
Documents |
Upload: | edgar-sonn |
View: | 221 times |
Download: | 1 times |
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…
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
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
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
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
8
Take Note: List Validation and Uniqueness
Excel-like validation formulaCan be specified on Columns and Lists
Example: =[Discount] < [Cost]
Column uniqueness constraint
9
Take Note: Query Throttling
Check query before executionNo index and count > limitJoins > limit
Can turn throttling off usingSPQuery.RequestThrottleOverrideSPSiteDataQuery.RequestThrottleOverride
10
New List CapabilitiesRelationshipsMulti-Value LookupsData Integrity & Data ValidationQuery Throttling
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>
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();
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>
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); } } } } }}
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
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
17
Expression Trees
LinQ to…
LinQ“runtime”
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)
19
LINQ to SQLfrom p in dataContext.Projectswhere p.Client.City == “Durban"select new { Name = p.Title, ClientName = p.Client.Title, Budget = p.BudgetHours };
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'
21
LINQ to SharePointfrom p in dataContext.Projectswhere p.Client.City == “Durban"select new { Name = p.Title, ClientName = p.Client.Title, Budget = p.BudgetHours };
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>
23
LINQ to SharePoint
demo
Accessing Relational SharePoint Data using LINQ to SharePoint
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
25
Overview / Summary
SQL MetalStrong TypingRelationshipsDeferred Execution (& client-side queries)Some limitations
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
27
Client OMServer Side
SharePoint
Server OM
SharePoint Web services
End ClientWin
SL
JS
Client OM
28
Client OM
demo
Accessing SharePoint Data using the Client OM
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)
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
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
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”
33
REST Basics
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
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'
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
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
38
Using the SharePoint REST (OData) APIs
demo
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
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
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)
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
43
(WTB305) Panel Discussion: Ask the experts about SharePoint
(OFC423) Developing a BCS External Content Type with Visual Studio 2010
Related Content
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?
Complete an evaluation via CommNet and Tag to win amazing prizes!
© 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.