1 / 18

The .NET Language Integrated Query Project

The .NET Language Integrated Query Project. Anders Hejlsberg TLN306 Technical Fellow Microsoft Corporation. Problem: Data != Objects. <book> <title/> <author/> <year/> <price/> </book>. SQL. WinFS. Objects. XML. The LINQ Project. C#. VB. Others….

butch
Télécharger la présentation

The .NET Language Integrated Query Project

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. The .NET LanguageIntegrated Query Project Anders Hejlsberg TLN306 Technical Fellow Microsoft Corporation

  2. Problem: Data != Objects

  3. <book> <title/> <author/> <year/> <price/> </book> SQL WinFS Objects XML The LINQ Project C# VB Others… .NET Language Integrated Query StandardQueryOperators DLinq(ADO.NET) XLinq (System.Xml)

  4. The LINQ Project

  5. Language Innovations c => c.Name • Lambda expressions • Extension methods • Local variable type inference • Object initializers • Anonymous types • Query expressions • Expression trees static void Dump(this object o); var x = 5; new Point { x = 1, y = 2 } new { c.Name, c.Phone } from … where … select Expression<T>

  6. Standard Query Operators

  7. custs names Where Select ID Name Phone c => c.City == "London" c => c.Name Deferred Query Execution Customer[] custs = SampleData.GetCustomers(); var query = from c in custs where c.City == "London" select c.Name; var query = custs.Where(c => c.City == "London").Select(c => c.Name); string[] names = query.ToArray();

  8. DLinq For Relational Data Accessing data today Queries in quotes SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new SqlCommand( @"SELECT c.Name, c.Phone FROM Customers c WHERE c.City = @p0"); cmd.Parameters.AddWithValue("@p0", "London“); DataReader dr = 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

  9. DLinq For Relational Data Accessing data with DLinq Classes describe data public class Customer { … } public class Northwind: DataContext { public Table<Customer> Customers; … } Tables are like collections Strongly typed connection 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

  10. DLinq For Relational Data • Language integrated data access • Maps tables and rows to classes and objects • Builds on ADO.NET and .NET Transactions • Mapping • Encoded in attributes • Relationships map to properties • Persistence • Automatic change tracking • Updates through SQL or stored procedures

  11. XLinq For XML Data Programming XML today Imperative model XmlDocument doc = new XmlDocument(); XmlElement contacts = doc.CreateElement("contacts"); foreach (Customer c in customers) if (c.Country == "USA") { XmlElement e = doc.CreateElement("contact"); XmlElement name = doc.CreateElement("name"); name.InnerText = c.CompanyName; e.AppendChild(name); XmlElement phone = doc.CreateElement("phone"); phone.InnerText = c.Phone; e.AppendChild(phone); contacts.AppendChild(e); } doc.AppendChild(contacts); Document centric No integrated queries Memory intensive <contacts> <contact> <name>Great Lakes Food</name> <phone>(503) 555-7123</phone> </contact> … </contacts>

  12. XLinq For XML Data Programming XML with XLinq Declarative model XElement contacts = new XElement("contacts", from c in customers where c.Country == "USA" select new XElement("contact", new XElement("name", c.CompanyName), new XElement("phone", c.Phone) ) ); Elementcentric Integrated queries Smaller and faster

  13. XLinq For XML Data • Language integrated query for XML • Expressive power of XPath / XQuery • But with C# or VB as programming language • Leverages experience with DOM • Element centric, not document centric • Functional construction • Text nodes are just strings • Simplified XML namespace support • Faster and smaller

  14. DLinq and XLinq

  15. The LINQ Project • Language Integrated Query for .NET • Native query syntax in C# 3.0 and VB 9.0 • Standard Query Operators • SQL-like queries for any .NET collection • DLinq • Query enabled data access framework • XLinq • Query enabled, smaller, faster XML DOM

  16. Benefits Of LINQ • Unified querying of objects, relational, XML • Type checking and IntelliSense for queries • SQL and XQuery-like power in C# and VB • Extensibility model for languages / APIs

  17. More Information http://msdn.microsoft.com/netframework/future/linq/

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

More Related