SlideShare una empresa de Scribd logo
1 de 28
LINQ to SharePoint
André Vala
andre.vala@create.pt
Agenda
• LINQ?
• LINQ to SharePoint?
• Developing with LINQ
• Common Pitfalls
• Performance
• Conclusion
2
LINQ?
3
LINQ PROVIDER DATA SOURCEAPPLICATION
B
C
A
.NET
.NET
QUERY
DATA
Language Integrated Query
LINQ to SQL
using System.Data.Linq;
DataContext db = new DataContext(@”mydatabase.mdf”);
Table<BankAccount> BankAccounts = db.GetTable<BankAccount>();
var query =
from account in BankAccounts
where account.Bank == “Deutsche Bank”
select account;
foreach (BankAccount account in query)
{
Console.WriteLine(“Number: {0}”, account.Number);
} 4
SHAREPOINT
LIST ITEMS
CAML
LINQ to SharePoint?
5
LINQ PROVIDER DATA SOURCEAPPLICATION
B
C
A
.NET
.NET
QUERY
DATA
SHAREPOINT
LINQ PROVIDER
Microsoft.SharePoint.Linq.dll
LINQ to SharePoint
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
EntityList<BankAccount> BankAccounts =
data.GetList<BankAccount>(“BankAccounts”);
var query =
from account in BankAccounts
where account.Bank == “Deutsche Bank”
select account;
foreach (BankAccount account in query)
{
Console.WriteLine(“Number: {0}”, account.Number);
}
6
DEMO HELLO LINQ!
7
Developing with LINQ
• Entities
• Add Items
• Delete Items
• Recycle Items
• Update Items
• Logging
8
Entities
BankAccount account = new BankAccount()
{
Number = “99100048169”,
Bank = “Deutsche Bank”
};
9
Content Type Entity Class
Column Attribute Member
Entities Manual Definition
[ContentType(Name=“BankAccount”, Id=“0x0104”)]
public partial class BankAccount
{
[Column(Name=“Number”, FieldType=“Text”)]
public string Number { get; set; }
[Column(Name=“Bank”, FieldType=“Text”)]
public string Bank { get; set; }
}
10
Entities Automatic Generation
SPMetal
Tool to generate entities for a set of content types / lists
Where is it?
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BIN
How is it used?
SPMetal
/web:http://myserver/myweb
/code:BankAccounts.cs
/namespace:MyApp.SharePoint.Data
11
Add Items
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
BankAccount account = new BankAccount()
{
Number = “99100048169”,
Bank = “Deutsche Bank”
};
data.BankAccounts.InsertOnSubmit(account);
data.SubmitChanges();
12
Delete Items
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
foreach (BankAccount account in data.BankAccounts)
{
if (account.Bank == “Deutsche Bank”)
data.BankAccounts.DeleteOnSubmit(account);
}
data.SubmitChanges();
13
Recycle Items
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
foreach (BankAccount account in data.BankAccounts)
{
if (account.Bank == “Deutsche Bank”)
data.BankAccounts.RecycleOnSubmit(account);
}
data.SubmitChanges();
14
Update Items
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
foreach (BankAccount account in data.BankAccounts)
{
if (account.Bank == “Deutsche Bank”)
account.Bank = “Bank of America”;
}
data.SubmitChanges();
15
Logging
using Microsoft.SharePoint.Linq;
DataContext data = new DataContext(SPContext.Current.Web.Url);
StringWriter writer = new StringWriter();
data.Log = writer;
// LINQ queries
(...)
string caml = writer.ToString();
16
DEMO LINQING
17
Common Pitfalls
• Anonymous Access
• Display Names
18
Pitfall Anonymous Access
• LINQ to SharePoint has no support for
anonymous access
• There is a workaround but has disadvantages:
– Large performance impact
– Uses RunWithElevatedPrivileges
• Solution: go back to CAML...
19
DEMO ANONYMOUS ACCESS
20
Pitfall Display Names
• SPMetal uses column Display Names to
generate class members
• What happens when the column names have
special characters? Weird things happen…
• How can we solve it?
21
DEMO DISPLAY NAMES
22
Performance
• Object Tracking Enabled
• LINQ vs CAML
23
Performance Object Tracking Enabled
Optimizes the performancein read-only scenarios...
DataContext data = new DataContext(SPContext.Current.Web.Url);
data.ObjectTrackingEnabled = false;
24
Performance LINQ vs CAML
• The LINQ to CAML translation is performed in
real time
• There is a performance penalty
• The generated query can be inefficient
• Not all the operations offered with LINQ are
supported in CAML...
25
DEMO PERFORMANCE
26
Conclusion
LINQ to SharePoint is really simple to use but
not the solution when...
• The code must run on the client
• The solution must support anonymous access
• Performance is paramount
• There are lookup columns that refer to lists in
other web sites of the same site collection
27
Thank You
André Vala
andre.vala@create.pt

Más contenido relacionado

La actualidad más candente

La actualidad más candente (6)

Reliable and Efficient Facebook data processing
Reliable and Efficient Facebook data processingReliable and Efficient Facebook data processing
Reliable and Efficient Facebook data processing
 
Credit Fraud Prevention with Spark and Graph Analysis
Credit Fraud Prevention with Spark and Graph AnalysisCredit Fraud Prevention with Spark and Graph Analysis
Credit Fraud Prevention with Spark and Graph Analysis
 
Melb nov17 Virtual Entity and auto number
Melb nov17 Virtual Entity and auto numberMelb nov17 Virtual Entity and auto number
Melb nov17 Virtual Entity and auto number
 
Web Browser Controls in Adlib: The Hidden Diamond in the Adlib Treasure Chest
Web Browser Controls in Adlib: The Hidden Diamond in the Adlib Treasure ChestWeb Browser Controls in Adlib: The Hidden Diamond in the Adlib Treasure Chest
Web Browser Controls in Adlib: The Hidden Diamond in the Adlib Treasure Chest
 
Workflow02
Workflow02Workflow02
Workflow02
 
GraphQL and Live Queries by Rodrigo Muñoz
GraphQL and Live Queries by Rodrigo MuñozGraphQL and Live Queries by Rodrigo Muñoz
GraphQL and Live Queries by Rodrigo Muñoz
 

Destacado (8)

Karine bosch andy-van_steenbergen-caml-spsbe12
Karine bosch andy-van_steenbergen-caml-spsbe12Karine bosch andy-van_steenbergen-caml-spsbe12
Karine bosch andy-van_steenbergen-caml-spsbe12
 
Social features in SharePoint 2013
Social features in SharePoint 2013Social features in SharePoint 2013
Social features in SharePoint 2013
 
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday HoustonCSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
CSOM (Client Side Object Model). Explained @ SharePoint Saturday Houston
 
Biwug 25092012 sp2013_itpro_hans_jaspers
Biwug 25092012 sp2013_itpro_hans_jaspersBiwug 25092012 sp2013_itpro_hans_jaspers
Biwug 25092012 sp2013_itpro_hans_jaspers
 
The SharePoint & jQuery Guide
The SharePoint & jQuery GuideThe SharePoint & jQuery Guide
The SharePoint & jQuery Guide
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechConDeep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
 

Similar a LINQ to SharePoint

Dev-In-Town:Linq To Sql by Chan Ming Man
Dev-In-Town:Linq To Sql by Chan Ming ManDev-In-Town:Linq To Sql by Chan Ming Man
Dev-In-Town:Linq To Sql by Chan Ming Man
Quek Lilian
 

Similar a LINQ to SharePoint (20)

Spug pt linqtosharepoint
Spug pt linqtosharepointSpug pt linqtosharepoint
Spug pt linqtosharepoint
 
MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)
 
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
Optimizing Code Reusability for SharePoint using Linq to SharePoint & the MVP...
 
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
AMIS Oracle OpenWorld en Code One Review 2018 - Pillar 2: Custom Application ...
 
AMIS Oracle OpenWorld & CodeOne Review - Pillar 2 - Custom Application Develo...
AMIS Oracle OpenWorld & CodeOne Review - Pillar 2 - Custom Application Develo...AMIS Oracle OpenWorld & CodeOne Review - Pillar 2 - Custom Application Develo...
AMIS Oracle OpenWorld & CodeOne Review - Pillar 2 - Custom Application Develo...
 
Stream Analytics with SQL on Apache Flink
 Stream Analytics with SQL on Apache Flink Stream Analytics with SQL on Apache Flink
Stream Analytics with SQL on Apache Flink
 
3.0
3.03.0
3.0
 
[Webinar] Interacting with BigQuery and Working with Advanced Queries
[Webinar] Interacting with BigQuery and Working with Advanced Queries[Webinar] Interacting with BigQuery and Working with Advanced Queries
[Webinar] Interacting with BigQuery and Working with Advanced Queries
 
From a hack to Data Mesh (Devoxx 2022)
From a hack to Data Mesh (Devoxx 2022)From a hack to Data Mesh (Devoxx 2022)
From a hack to Data Mesh (Devoxx 2022)
 
Dev-In-Town:Linq To Sql by Chan Ming Man
Dev-In-Town:Linq To Sql by Chan Ming ManDev-In-Town:Linq To Sql by Chan Ming Man
Dev-In-Town:Linq To Sql by Chan Ming Man
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET Developer
 
How to mutate your immutable log | Andrey Falko, Stripe
How to mutate your immutable log | Andrey Falko, StripeHow to mutate your immutable log | Andrey Falko, Stripe
How to mutate your immutable log | Andrey Falko, Stripe
 
Emergent architecture- a casestudy TREDS
Emergent architecture- a casestudy TREDSEmergent architecture- a casestudy TREDS
Emergent architecture- a casestudy TREDS
 
Spark, GraphX, and Blockchains: Building a Behavioral Analytics Platform for ...
Spark, GraphX, and Blockchains: Building a Behavioral Analytics Platform for ...Spark, GraphX, and Blockchains: Building a Behavioral Analytics Platform for ...
Spark, GraphX, and Blockchains: Building a Behavioral Analytics Platform for ...
 
LF_APIStrat17_Breaking a Monolith: In-Place Refactoring with Service-Oriented...
LF_APIStrat17_Breaking a Monolith: In-Place Refactoring with Service-Oriented...LF_APIStrat17_Breaking a Monolith: In-Place Refactoring with Service-Oriented...
LF_APIStrat17_Breaking a Monolith: In-Place Refactoring with Service-Oriented...
 
Breaking a monolith: In-place refactoring with service-oriented architecture ...
Breaking a monolith: In-place refactoring with service-oriented architecture ...Breaking a monolith: In-place refactoring with service-oriented architecture ...
Breaking a monolith: In-place refactoring with service-oriented architecture ...
 
Why Standards-Based Drivers Offer Better API Integration
Why Standards-Based Drivers Offer Better API IntegrationWhy Standards-Based Drivers Offer Better API Integration
Why Standards-Based Drivers Offer Better API Integration
 
Why Standards-Based Drivers Offer Better API Integration
Why Standards-Based Drivers Offer Better API IntegrationWhy Standards-Based Drivers Offer Better API Integration
Why Standards-Based Drivers Offer Better API Integration
 
Microsoft & Open Source - a 'brave new world' - ProgSCon 2017
Microsoft & Open Source - a 'brave new world' - ProgSCon 2017Microsoft & Open Source - a 'brave new world' - ProgSCon 2017
Microsoft & Open Source - a 'brave new world' - ProgSCon 2017
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object Model
 

Más de André Vala

Más de André Vala (20)

RGPD - Testemunho do Mundo Real
RGPD - Testemunho do Mundo RealRGPD - Testemunho do Mundo Real
RGPD - Testemunho do Mundo Real
 
Office Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft TeamsOffice Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft Teams
 
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
 
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint WebhooksFrom Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks
 
Planning the Death Star with Microsoft Planner
Planning the Death Star with Microsoft PlannerPlanning the Death Star with Microsoft Planner
Planning the Death Star with Microsoft Planner
 
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint WebhooksFrom Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks
 
Microsoft Planner Deep Dive
Microsoft Planner Deep DiveMicrosoft Planner Deep Dive
Microsoft Planner Deep Dive
 
SharePoint - Presente e Futuro
SharePoint - Presente e FuturoSharePoint - Presente e Futuro
SharePoint - Presente e Futuro
 
Office 365 Groups Deep Dive
Office 365 Groups Deep DiveOffice 365 Groups Deep Dive
Office 365 Groups Deep Dive
 
Soluções com Office Graph
Soluções com Office GraphSoluções com Office Graph
Soluções com Office Graph
 
Host-Named Site Collections in SharePoint 2013
Host-Named Site Collections in SharePoint 2013Host-Named Site Collections in SharePoint 2013
Host-Named Site Collections in SharePoint 2013
 
User License Enforcement em SharePoint 2013
User License Enforcement em SharePoint 2013User License Enforcement em SharePoint 2013
User License Enforcement em SharePoint 2013
 
How To Use Host-Named Site Collections
How To Use Host-Named Site CollectionsHow To Use Host-Named Site Collections
How To Use Host-Named Site Collections
 
Novidades na pesquisa no SharePoint 2013
Novidades na pesquisa no SharePoint 2013Novidades na pesquisa no SharePoint 2013
Novidades na pesquisa no SharePoint 2013
 
Building Public Web Sites in SharePoint 2010
Building Public Web Sites in SharePoint 2010 Building Public Web Sites in SharePoint 2010
Building Public Web Sites in SharePoint 2010
 
SharePoint + Azure = Better Together
SharePoint + Azure = Better TogetherSharePoint + Azure = Better Together
SharePoint + Azure = Better Together
 
Federated Authentication in SharePoint 2010
Federated Authentication in SharePoint 2010Federated Authentication in SharePoint 2010
Federated Authentication in SharePoint 2010
 
Using BCS to integrate Azure Services with SharePoint 2010
Using BCS to integrate Azure Services with SharePoint 2010Using BCS to integrate Azure Services with SharePoint 2010
Using BCS to integrate Azure Services with SharePoint 2010
 
Solução de Negócio baseadas em Office 2010 e SharePoint 2010
Solução de Negócio baseadas em Office 2010 e SharePoint 2010Solução de Negócio baseadas em Office 2010 e SharePoint 2010
Solução de Negócio baseadas em Office 2010 e SharePoint 2010
 
SharePoint Deployment
SharePoint DeploymentSharePoint Deployment
SharePoint Deployment
 

Último

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

LINQ to SharePoint

  • 1. LINQ to SharePoint André Vala andre.vala@create.pt
  • 2. Agenda • LINQ? • LINQ to SharePoint? • Developing with LINQ • Common Pitfalls • Performance • Conclusion 2
  • 3. LINQ? 3 LINQ PROVIDER DATA SOURCEAPPLICATION B C A .NET .NET QUERY DATA Language Integrated Query
  • 4. LINQ to SQL using System.Data.Linq; DataContext db = new DataContext(@”mydatabase.mdf”); Table<BankAccount> BankAccounts = db.GetTable<BankAccount>(); var query = from account in BankAccounts where account.Bank == “Deutsche Bank” select account; foreach (BankAccount account in query) { Console.WriteLine(“Number: {0}”, account.Number); } 4
  • 5. SHAREPOINT LIST ITEMS CAML LINQ to SharePoint? 5 LINQ PROVIDER DATA SOURCEAPPLICATION B C A .NET .NET QUERY DATA SHAREPOINT LINQ PROVIDER Microsoft.SharePoint.Linq.dll
  • 6. LINQ to SharePoint using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); EntityList<BankAccount> BankAccounts = data.GetList<BankAccount>(“BankAccounts”); var query = from account in BankAccounts where account.Bank == “Deutsche Bank” select account; foreach (BankAccount account in query) { Console.WriteLine(“Number: {0}”, account.Number); } 6
  • 8. Developing with LINQ • Entities • Add Items • Delete Items • Recycle Items • Update Items • Logging 8
  • 9. Entities BankAccount account = new BankAccount() { Number = “99100048169”, Bank = “Deutsche Bank” }; 9 Content Type Entity Class Column Attribute Member
  • 10. Entities Manual Definition [ContentType(Name=“BankAccount”, Id=“0x0104”)] public partial class BankAccount { [Column(Name=“Number”, FieldType=“Text”)] public string Number { get; set; } [Column(Name=“Bank”, FieldType=“Text”)] public string Bank { get; set; } } 10
  • 11. Entities Automatic Generation SPMetal Tool to generate entities for a set of content types / lists Where is it? C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BIN How is it used? SPMetal /web:http://myserver/myweb /code:BankAccounts.cs /namespace:MyApp.SharePoint.Data 11
  • 12. Add Items using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); BankAccount account = new BankAccount() { Number = “99100048169”, Bank = “Deutsche Bank” }; data.BankAccounts.InsertOnSubmit(account); data.SubmitChanges(); 12
  • 13. Delete Items using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); foreach (BankAccount account in data.BankAccounts) { if (account.Bank == “Deutsche Bank”) data.BankAccounts.DeleteOnSubmit(account); } data.SubmitChanges(); 13
  • 14. Recycle Items using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); foreach (BankAccount account in data.BankAccounts) { if (account.Bank == “Deutsche Bank”) data.BankAccounts.RecycleOnSubmit(account); } data.SubmitChanges(); 14
  • 15. Update Items using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); foreach (BankAccount account in data.BankAccounts) { if (account.Bank == “Deutsche Bank”) account.Bank = “Bank of America”; } data.SubmitChanges(); 15
  • 16. Logging using Microsoft.SharePoint.Linq; DataContext data = new DataContext(SPContext.Current.Web.Url); StringWriter writer = new StringWriter(); data.Log = writer; // LINQ queries (...) string caml = writer.ToString(); 16
  • 18. Common Pitfalls • Anonymous Access • Display Names 18
  • 19. Pitfall Anonymous Access • LINQ to SharePoint has no support for anonymous access • There is a workaround but has disadvantages: – Large performance impact – Uses RunWithElevatedPrivileges • Solution: go back to CAML... 19
  • 21. Pitfall Display Names • SPMetal uses column Display Names to generate class members • What happens when the column names have special characters? Weird things happen… • How can we solve it? 21
  • 23. Performance • Object Tracking Enabled • LINQ vs CAML 23
  • 24. Performance Object Tracking Enabled Optimizes the performancein read-only scenarios... DataContext data = new DataContext(SPContext.Current.Web.Url); data.ObjectTrackingEnabled = false; 24
  • 25. Performance LINQ vs CAML • The LINQ to CAML translation is performed in real time • There is a performance penalty • The generated query can be inefficient • Not all the operations offered with LINQ are supported in CAML... 25
  • 27. Conclusion LINQ to SharePoint is really simple to use but not the solution when... • The code must run on the client • The solution must support anonymous access • Performance is paramount • There are lookup columns that refer to lists in other web sites of the same site collection 27

Notas del editor

  1. This demo shows how to build a simple LINQ query to retrieve data from a SharePoint list.
  2. This demos shows the basics of using LINQ to SharePoint to Add, Update, Delete and Recycle list items.
  3. This demos shows why Anonymous Acess is not supported in LINQ to SharePoint and how you can get around it.
  4. This demo shows how to generate entities with SPMetal without using the column display names.
  5. This demo shows how LINQ to SharePoint compares to CAML performance-wise.