LINQ: It - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

LINQ: It

Description:

Provide overview of the LINQ project. Demonstrate basic ... var contacts = from c in db.Customers. where c.City == 'London' select new { c.Name, c.Phone } ... – PowerPoint PPT presentation

Number of Views:209
Avg rating:3.0/5.0
Slides: 21
Provided by: dennyb
Category:
Tags: linq | var

less

Transcript and Presenter's Notes

Title: LINQ: It


1
LINQ Its Not Your Fathers Data Access
  • Denny Boynton
  • Anheuser-Busch Companies

2
Goals
  • Provide overview of the LINQ project
  • Demonstrate basic functionality of LINQ
  • Point out learning resources for self study

3
What is LINQ?
  • Language Integrated Query
  • Evolution of application data management
  • Coming with C 3.0 and VB.NET 9.0

Anders Hejlsberg
Don Box
4
The Problem
  • Worlds of OO and data access are far, far apart
  • OO language types and native database types are
    often different
  • SQL code is inside the quotes
  • No strong typing or compile-time type checking
  • No Intellisense
  • No Statement completion
  • SQL and XML have query languages, objects to not

LINQ seeks to bridge the gap
5
What is LINQ?
C
VB
Others
.NET Language Integrated Query
StandardQueryOperators
DLinq(ADO.NET)
XLinq (System.Xml)
Source Anders Hejlsbergs PDC Presentation
6
Demo
  • Examine the basics of LINQ

7
Language Enhancements
  • Lambda Expressions
  • Extension Methods
  • Local Variable Type Inference
  • Object Initializers
  • Anonymous Types
  • Query Expressions

C gt c.Name
c.Customers.Where().Select()
var n 5
New c.Name, c.Phone
from..whereselect
new Point x1, y2
8
Standard Query Operators
Source Anders Hejlsbergs PDC Presentation
9
DLinq
  • A means of managing relational data

Queries in quotes
Accessing data today
SqlConnection c new SqlConnection() c.Open()
SqlCommand cmd new SqlCommand( _at_"SELECT
c.Name, c.Phone FROM Customers c
WHERE c.City _at_p0") cmd.Parameters.AddWithValue(
"_at_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
10
DLinq
Accessing data with DLinq
Classes describe data
public class Customer public class
Northwind DataContext public
TableltCustomergt 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
11
DLinq
  • 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

12
XLinq
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
ltcontactsgt ltcontactgt ltnamegtGreat Lakes
Foodlt/namegt ltphonegt(503) 555-7123lt/phonegt
lt/contactgt lt/contactsgt
13
XLinq
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
14
XLinq
  • 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

15
Demo
  • Show DLinq and XLinq in action

16
What is LINQ?
  • The LINQ project is
  • Language Integrated Query for .NET
  • Native query syntax for .NET languages
  • Standard Query Operators
  • SQL-like method extensions for any .NET
    collection
  • System.Query namespace
  • DLinq
  • Code name for future version of ADO.NET
  • Query enabled data access framework
  • System.Data.Xlinq namespace
  • XLinq
  • Query enabled, smaller, faster XML DOM
  • System.XML.Xlinq namespace

17
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

18
Closing Thoughts
  • Not sure where use of LINQ will coincide with SQL
  • Use may well be driven by data management
    standards of an organization
  • Where should data access really live
  • ORM synchronization
  • This could really be a revolution

19
Resources
  • LINQ Project Home Page
  • http//msdn.microsoft.com/data/ref/linq/
  • Anders Hejlsberg LINQ
  • http//channel9.msdn.com/showpost.aspx?postid1146
    80
  • LINQ Project Overview Whitepaper
  • http//msdn.microsoft.com/data/ref/linq/default.as
    px?pull/library/en-us/dndotnet/html/linqprojectov
    w.asp

20
  • Thank You
  • Denny Boynton
  • Email denny_at_boyntons.com
Write a Comment
User Comments (0)
About PowerShow.com