1 / 19

LinqToSharePoint SandBoxed Solution Shakir Majeed Khan sharepointtechies.wordpress/

LinqToSharePoint SandBoxed Solution Shakir Majeed Khan http://sharepointtechies.wordpress.com/. MySelf. User Group Leader of SharePoint Techies, Working independently on SharePoint technologies.

rendor
Télécharger la présentation

LinqToSharePoint SandBoxed Solution Shakir Majeed Khan sharepointtechies.wordpress/

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LinqToSharePointSandBoxed SolutionShakirMajeedKhanhttp://sharepointtechies.wordpress.com/

  2. MySelf • 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.  http://junooni.wordpress.com/ shakir.majeed@gmail.com www.facebook.com/shakir.majeed

  3. Agenda • session is divided into two • LinqtoSharePoint • SandBoxed Solution • Questions

  4. What’s wrong with this Queries in quotes SqlConnection c = new SqlConnection(…); c.Open(); SqlCommandcmd = new SqlCommand( @"SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0"); cmd.Parameters.AddWithValue("@p0", "London“); DataReaderdr = c.Execute(cmd); while (dr.Read()) { string name = dr.GetString(0); string phone = dr.GetString(1); DateTime date = dr.GetDateTime(2); } dr.Close(); Loosely bound arguments Loosely typed result sets No compile time checks

  5. What’s wrong with this

  6. LINQ (pronounced Link): Language INtegratedQuery

  7. What is LINQ? • Language Integrated Query • Simplified, object-oriented way to query • Bridges OOP and relational data • Compile-time checked queries • Provides IntelliSense inside Visual Studio • Unified syntax for querying any data source

  8. Linq to SQL Classes describe data public class Customer { … } public class Northwind : DataContext { public Table<Customer> Customers; … } Tables are like collections Strongly typed connections Northwind db = new Northwind(…); var contacts = from c in db.Customers where c.City == "London" select new { c.Name, c.Phone }; Integrated query syntax Strongly typed results

  9. CAML(Collaborative Application MarkUp Language) SPWebweb; SPQueryquery= newSPQuery(); query.Query= String.Format(“<Where>  <And>  <Eq>         <FieldRef Name='LastName' />     <Value Type='Text'>Shakir</Value>   </Eq>     <Geq>        <FieldRef Name='Age' />    <Value Type='Number'>16</Value>  </Geq>  </And> </Where>”) SPListItemCollectionlColl= web.Lists[“Employee”].GetItems(query); Queries in quotes Loosely bound arguments No compile time checks

  10. Demo

  11. C# Enhancments for LINQ • IEnumerable<T>, IQueryable<T> • Automatic Properties • Object and Collection Initializers • Lambda Expressions • Query Syntax • Anonymous Types

  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. Automatic Properties • Allows short-hand property declarations • Compiler emits getters and setters • Used in LINQ to surface properties public class Contact { public string FirstName { get; set; }  public string LastName  { get; set; }        }

  14. Object and Collection Initializers //Traditional approach Contact c= new Contact(); c.FirstName = “shakir"; c.LastName = “majeed "; //Object Initializer Contact c= new Contact{ FirstName=“shakir", LastName=“Majeed " }; //Collection Initializer List<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. Lambda Expressions • Compact way to write anonymous functions // passing parameter using an anonymous delegate IEnumerable<Contact> results = contacts.Where( delegate(Contact c) {return c.FirstName==“shakir”;} ); // equivalent code using a lambda expression IEnumerable<Contact> results = contacts.Where( c => FirstName=="shakir" );

  16. Query Syntax • Offers a readable alternative to Method syntax IEnumerable<Contact> results = contacts.Where( c=> FirstName=="shakir"); IEnumerable<Contact> results = from c in contacts where c.FirstName.Equals("shakir");

  17. Anonymous Types • Allows developers to use variables without declaring the type. • Still strongly typed, but inferred var results = from c in contacts where c.FirstName.Equals("Mike");

  18. Demo

  19. Thank You Facebook: http://www.facebook.com/shakir.majeed Blog: http://junooni.wordpress.com/ Email: shakir.majeed@gmail.com

More Related