LinqToSharePointSandBoxed SolutionShakir Majeed Khanhttp://sharepointtechies.wordpress.com/
MySelfhttp://junooni.wordpress.com/shakir.majeed@gmail.comwww.facebook.com/shakir.majeed      User Group Leader of      Sh...
Agenda session is divided into two   LinqtoSharePoint   SandBoxed Solution Questions
What’s wrong with this                                                   Queries in SqlConnection c = new SqlConnection(…)...
What’s wrong with this
LINQ (pronounced Link):Language INtegrated Query
Language Integrated QuerySimplified, object-oriented way to queryBridges OOP and relational dataCompile-time checked queri...
Linq to SQL                                          Classes public class Customer { … }            describe data public c...
CAML(Collaborative ApplicationMarkUp Language)SPWeb web;SPQueryquery = newSPQuery();                Queries in            ...
Demo
C# Enhancments for LINQ IEnumerable<T>, IQueryable<T> Automatic Properties Object and Collection Initializers Lambda Expre...
IEnumerable<T>, IQueryable<T>   Contained in System.Collections.Generic   Implemented by the query provider   Supports a s...
Automatic Properties  Allows short-hand property declarations  Compiler emits getters and setters  Used in LINQ to surface...
Object and Collection Initializers//Traditional approachContact c= new Contact();c.FirstName = “shakir";c.LastName = “maje...
Lambda Expressions    Compact way to write anonymous functions// passing parameter using an anonymous delegateIEnumerable<...
Query Syntax   Offers a readable alternative to Method syntaxIEnumerable<Contact> results =  contacts.Where( c=> FirstName...
Anonymous Types  Allows developers to use variables without  declaring the type.  Still strongly typed, but inferredvar re...
Demo
Thank YouFacebook: http://www.facebook.com/shakir.majeedBlog: http://junooni.wordpress.com/Email: shakir.majeed@gmail.com
Upcoming SlideShare
Loading in...5
×

Share pointtechies linqtosp-andsbs

561

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
561
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This slide shows the language enhancements for C# that directly support LINQ. These enhancements make it possible to write compact LINQ queries in a single statement.
  • Short hand properties with no member variables
  • Again, short hand with no member variables
  • var keyword
  • Share pointtechies linqtosp-andsbs

    1. 1. LinqToSharePointSandBoxed SolutionShakir Majeed Khanhttp://sharepointtechies.wordpress.com/
    2. 2. MySelfhttp://junooni.wordpress.com/shakir.majeed@gmail.comwww.facebook.com/shakir.majeed User Group Leader of SharePoint Techies, Working independently on SharePoint technologies. Trainer for Microsoft Office SharePoint Server 2007 and Window SharePoint Services 3.0 at AUC Technologies.
    3. 3. Agenda session is divided into two LinqtoSharePoint SandBoxed Solution Questions
    4. 4. What’s wrong with this Queries in SqlConnection c = new SqlConnection(…); quotes c.Open(); SqlCommand cmd = new SqlCommand( @"SELECT c.Name, c.Phone Loosely bound FROM Customers c arguments WHERE c.City = @p0"); cmd.Parameters.AddWithValue("@p0", "London“); DataReader dr = c.Execute(cmd); Loosely typed while (dr.Read()) { result sets string name = dr.GetString(0); string phone = dr.GetString(1); DateTime date = dr.GetDateTime(2); No compile time } checks dr.Close();
    5. 5. What’s wrong with this
    6. 6. LINQ (pronounced Link):Language INtegrated Query
    7. 7. Language Integrated QuerySimplified, object-oriented way to queryBridges OOP and relational dataCompile-time checked queriesProvides IntelliSense inside Visual StudioUnified syntax for querying any data source
    8. 8. Linq to SQL Classes public class Customer { … } describe data public class Northwind : DataContext Tables are like { collections public Table<Customer> Customers; … } Strongly typed connections Northwind db = new Northwind(…); var contacts = Integrated from c in db.Customers query syntax where c.City == "London" select new { c.Name, c.Phone }; Strongly typed results
    9. 9. CAML(Collaborative ApplicationMarkUp Language)SPWeb web;SPQueryquery = newSPQuery(); Queries in quotesquery.Query= String.Format(“<Where><And> <Eq><FieldRef Name=LastName /><Value Type=Text>Shakir</Value></Eq> <Geq><FieldRef Name=Age /> Loosely bound<Value Type=Number>16</Value> arguments</Geq> </And></Where>”) No compile timeSPListItemCollectionl Coll= checksweb.Lists[“Employee”].GetItems(query);
    10. 10. Demo
    11. 11. C# Enhancments for LINQ IEnumerable<T>, IQueryable<T> Automatic Properties Object and Collection Initializers Lambda Expressions Query Syntax Anonymous Types
    12. 12. IEnumerable<T>, IQueryable<T> Contained in System.Collections.Generic Implemented by the query provider Supports a simple iteration or a query against that type This is what allows LINQ to query
    13. 13. Automatic Properties Allows short-hand property declarations Compiler emits getters and setters Used in LINQ to surface propertiespublic class Contact { public string FirstName { get; set; } public string LastName { get; set; }}
    14. 14. Object and Collection Initializers//Traditional approachContact c= new Contact();c.FirstName = “shakir";c.LastName = “majeed ";//Object InitializerContact c= new Contact{ FirstName=“shakir", LastName=“Majeed "};//Collection InitializerList<Contact> contacts = new List<Contact>{ Contact c= new Contact{ FirstName=“shakir", LastName=“majeed"}, Contact c= new Contact{ FirstName=“aamir", LastName=“majeed" }, Contact c= new Contact{ FirstName=“zakir", LastName=“majeed" },};
    15. 15. Lambda Expressions Compact way to write anonymous functions// passing parameter using an anonymous delegateIEnumerable<Contact> results = contacts.Where( delegate(Contact c) {return c.FirstName==“shakir”;} );// equivalent code using a lambda expressionIEnumerable<Contact> results = contacts.Where( c => FirstName=="shakir" );
    16. 16. Query Syntax Offers a readable alternative to Method syntaxIEnumerable<Contact> results = contacts.Where( c=> FirstName=="shakir");IEnumerable<Contact> results = from c in contacts where c.FirstName.Equals("shakir");
    17. 17. Anonymous Types Allows developers to use variables without declaring the type. Still strongly typed, but inferredvar results = from c in contacts where c.FirstName.Equals("Mike");
    18. 18. Demo
    19. 19. Thank YouFacebook: http://www.facebook.com/shakir.majeedBlog: http://junooni.wordpress.com/Email: shakir.majeed@gmail.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×