using linq with net compact framework l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Using LINQ with .NET Compact Framework PowerPoint Presentation
Download Presentation
Using LINQ with .NET Compact Framework

Loading in 2 Seconds...

play fullscreen
1 / 21
tyra

Using LINQ with .NET Compact Framework - PowerPoint PPT Presentation

142 Views
Download Presentation
Using LINQ with .NET Compact Framework
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. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Using LINQ with .NET Compact Framework Manav Gaur Program Manager Microsoft India

  2. Agenda • Overview • LINQ Architecture • LINQ Queries • Demos • Objects • XML • Dataset • Questions & Answers

  3. Today’s Software Development • Data is fragmented • Objects • XML • Relational • Data != Object • Different programming models for each • Imperative programming—describes how, not what to do

  4. .NET Language-Integrated Query • General-purpose query processor built right into your favorite programming language. • Flexible • Extensible • SQL like syntax • LINQ defines standard query operators that allow • Traversal • Filter • Projection Operations • Easy to use for increased productivity • Type safe • Syntax check • IntelliSense support • Terse declarative style—define what to do, not how to do it • Unifies various types of data access

  5. LINQ Architecture on .NETCF C# VB.NET Others… .NET Language Integrated Query (LINQ) LINQ enabled data sources LINQ enabled ADO.NET LINQ To DataSet LINQ To Entities LINQ To SQL LINQ To XML LINQ To Objects Relational <book> <title/> <author/> <price/> </book> Objects XML

  6. LINQ Queries Local variable type inference Filter Conditions Results Ordering IEnumerable<Customer> q = from c in customers select c; var q = from c in customers select c; var q = from c in customers where c.City == “Mumbai” select c; var q = from c in customers where c.City == “Mumbai” orderbyc.Name select c;

  7. More LINQ Queries Anonymous Type Object Initialization Lambda Expression Extension Methods var q = from c in customers where c.City == “Mumbai” orderbyc.Name select new {c.Name, c.Phone}; var q = customers .Where (c => c.City == “Mumbai”) .Orderby(c => c.Name) .Select ( c => new {c.Name, c.Phone});

  8. Query Expressions Zero or more from, join, let, where, or orderby Starts with from fromidinsource { fromidinsource | joinidinsourceonexprequalsexpr [ intoid ] | letid = expr | wherecondition | orderbyordering, ordering, … } selectexpr | groupexprbykey [ intoidquery ] Use let to declare temporary variables Ends with selector group by Optional into continuation

  9. LINQ to Objects Operates on any IEnumerable<T> collection Wide range of operators available Operators can be added by developers

  10. Days Before LINQ… JAIPUR MUMBAI NAGPUR using System; using System.Collections; using System.Collections.Generic; class app { static void Main() { string[] cities = {“Delhi", “Mumbai", “Pune", “Nagpur", “Chennai", “Bangalore", “Jaipur" }; List<String> list = new List<String>(); foreach (string s in cities) if (s.Length == 6) list.Add(s.ToUpper()); list.Sort(); foreach (string s in list) Console.WriteLine(s); } }

  11. And Now, with LINQ using System; using System.Linq; using System.Collections.Generic; class app { static void Main() { string[] cities ={ “Delhi, “Mumbai, “Pune”, “Nagpur”, “Chennai”, “Bangalore, “Jaipur” }; IEnumerable<string> expr = from s in cities wheres.Length == 6 orderby s selects.ToUpper(); foreach (string item in expr) Console.WriteLine(item); } } JAIPUR MUMBAI NAGPUR

  12. DEMOLINQ to Objects

  13. LINQ to XML New XML API Standard query operations against XML elements Compact, fast, and uses less memory Create XML easily, use LINQ query output Transform XML

  14. Before LINQ XmlDocument doc = new XmlDocument(); XmlElement books = doc.CreateElement("Books"); XmlElement book = doc.CreateElement("Book"); XmlElement title = doc.CreateElement("Title"); XmlElement price = doc.CreateElement("Price"); doc.AppendChild(books); books.AppendChild(book); book.AppendChild(title); book.AppendChild(price); title.AppendChild( doc.CreateTextNode("Short DOM reference, vol.5")); price.AppendChild(doc.CreateTextNode("99.95")); doc.Save(“MyBooks.xml”); <Books> <Book> <Title>Short DOM reference, vol.5</Title> <Price>99.95</Price> </Book> </Books>

  15. After LINQ XDocument doc = new XDocument( new XElement("Books", new XElement("Book", new XElement("Title", "What to do in spare time freed up from XML programming."), new XElement("Price", "19.95") ) ) ) doc.Save(“MyBooks.xml”); <Books> <Book> <Title>What to do in spare time freed up from XML programming.</Title> <Price>19.95</Price> </Book> </Books>

  16. DEMOLINQ to XML

  17. LINQ to DataSet • Run standard query operators over DataSet • Reuse and extend your existing ADO.NET-based code • Do hard things—like joining tables—easily

  18. DEMOLINQ to DataSet

  19. Summary • Powerful and convenient language innovations • Easy-to-use expressions • Compile-time type and error checking, IntelliSense • New modern, redesigned XML API • Easier and lighter than DOM • Unified query model for objects, XML and relational data sources

  20. Call to Action • Install and use Visual Studio code name “Orcas” Beta 1 • .NET Compact Framework v3.5 Beta 1 • .NET Compact Framework v2 SP2 • Download and use v2 SP2 in Visual Studio 2005 • Download 101 LINQ Samples • http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx • Send us your feedback • http://connect.microsoft.com/VisualStudio/Feedback • http://blogs.msdn.com/vsdteam • http://blogs.msdn.com/mgaur • mgaur@microsoft.com

  21. © 2007 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.