240 likes | 368 Views
Language Integrated Query (LINQ). Mike Taulty Developer & Platform Group Microsoft Ltd Mike.Taulty@microsoft.com http://www.mtaulty.com. Agenda. When & How Is This Shipping? What’s the Problem? What’s the Solution? The LINQ Pattern How is this added to the languages?
E N D
Language Integrated Query(LINQ) Mike Taulty Developer & Platform Group Microsoft Ltd Mike.Taulty@microsoft.com http://www.mtaulty.com
Agenda • When & How Is This Shipping? • What’s the Problem? • What’s the Solution? • The LINQ Pattern • How is this added to the languages? • Implementations of the pattern • “LINQ to .....................”
Visual Studio “Orcas” • Next version of Visual Studio • Better for Web, Office, Vista, Data, Fx 3.0 • Ships with Framework V3.5 • Ships with C# V3.0, Visual Basic 9.0 • Dates • 2-3 CTPs out, Beta 1 just dropped • Shipping this year?
Querying Today: Loop, Filter, Sort, Group...
Loop, Filter, Sort, Group... • Too much code still looks like this...
Querying Today: Data is different
“Opaque” Data Access API’s We solve the problem with a string... "/descendant-or-self/..." We solve the problem with a string... "SELECT * FROM ..." We get back an opaque data type XmlNode We get back an opaque data type DataTable, DataReader XML Relational "The Data Barrier" My Code
Strings Hide Complexity These errors show up at runtime, not compile time
“Orcas” Language Integrated QueryMoving query capabilities into the languages fromitemNameinsrcExpr join itemNameinsrcExpronkeyExprequalskeyExpr (intoitemName)? letitemName= selExpr wherepredExpr orderby(keyExpr(ascending| descending)?)* selectselExpr group selExprbykeyExpr intoitemName query-body
"Language" Features Enable Query • Object initialisers • Collection initialisers • Implicit Typing • Anonymous Types • Lambda • Expressions • Statements • Extension methods • Expression trees • IEnumerable<T> • IQueryable<T>
Extensibility IEnumerable & IQueryable
IEnumerable<T>? Object fromitemNameinsrcExpr wherepredExpr orderby(keyExpr(ascending| descending)?)* selectselExpr ... Object Object Object Object Object where Object Object orderby Object select
IQueryable<T>? Object fromitemNameinsrcExpr wherepredExpr orderby(keyExpr(ascending| descending)?)* selectselExpr ... Object Object Object where where where orderby orderby Object Object Object Object Object select
LINQ to XML 1 LINQ Pattern fromitemNameinsrcExpr join itemNameinsrcExpronkeyExprequalskeyExpr (intoitemName)? letitemName= selExpr wherepredExpr orderby(keyExpr(ascending| descending)?)* selectselExpr group selExprbykeyExpr intoitemName query-body New XML API
System.Xml.Linq • New XML API (more DOM than reader) • Key classes: XElement, XAttribute
LINQ to SQL 2 LINQ Pattern fromitemNameinsrcExpr join itemNameinsrcExpronkeyExprequalskeyExpr (intoitemName)? letitemName= selExpr wherepredExpr orderby(keyExpr(ascending| descending)?)* selectselExpr group selExprbykeyExpr intoitemName query-body Object Relational Mapping API Code Gen Tools
Summary • Powerful, intuitive LINQ pattern • One "syntax" to learn • Relational, hierarchical, object data • Underpinned by new or existing API's • For Relational Data • LINQ to SQL • ORM over database schema • LINQ to Entities • ORM over abstracted conceptual model • LINQ to DataSet