LINQ Providers - PowerPoint PPT Presentation

About This Presentation
Title:

LINQ Providers

Description:

Supports SAX-style reading/writing of documents with the use of XStreamingElement ... Use LINQ in current applications without re-writing using LINQ to SQL ... – PowerPoint PPT presentation

Number of Views:140
Avg rating:3.0/5.0
Slides: 18
Provided by: itboxingc
Learn more at: https://www.devbg.org
Category:

less

Transcript and Presenter's Notes

Title: LINQ Providers


1
LINQ Providers
Or why .NET rules, and Java doesnt
Branimir Giurov
SofiaDev.org UG Lead, C MVP Freelance Software
Developer
www.sofiadev.org
2
Contents
  • typeof(linq)
  • How does it work?
  • Lambda, extension methods, iterators

3
typeof(linq)
4
C 3.0
VB 9.0
Others
.NET Language Integrated Query
LINQ toObjects
LINQ toSQL
LINQ toXML
LINQ toEntities
LINQ toDatasets
5
typeof(linq)
  • LINQ to Objects
  • LINQ to SQL
  • LINQ to XML
  • LINQ to Datasets
  • LINQ to Entities
  • LINQ to Windows Search
  • LINQ to Google
  • LINQ to Sharepoint
  • LINQ to nHibernate

6
LINQ to Objects
  • Query language over collections of objects
  • Standard SQL-like set of query operators,
    including joins and grouping
  • New query operators can be added, fully
    extensible (extension methods)
  • Intellisense and compiler syntax checking support
    in Visual Studio

7
LINQ to Objects
  • How to query an array of int?

public void Linq1()     int numbers 5, 4,
1, 3, 9, 8, 6, 7, 2, 0     var lowNums
        from n in numbers        where n lt
5        select n    Console.WriteLine("Number
s lt 5")    foreach (var x in lowNums)
        Console.WriteLine(x)    
8
LINQ to SQL
  • Write queries in any .NET language to retrieve
    and manipulate data from SQL
  • Use FK constraints for defining relations of data
    without joins
  • Join in code on any column that has no FK defined
  • Use FKs to query/modify data in SQL DB
  • Call SubmitChanges() when youre done
  • Currently supports SQL 2000 2005
  • System.Date.Linq.SqlClient.Sql2000Provider
  • System.Date.Linq.SqlClient.Sql2005Provider

9
DEMO
LINQ to SQL ToString() Modifying Queries Mapping
Styles Mapping Tools
10
LINQ to XML
  • LINQ to XML is a new way to construct, write and
    read XML data in the .NET language of the
    developers choice
  • Simplifies working with XML
  • No more XPath or XSLT
  • Not a replacement for DOM or any of the current
    XML libs
  • Supports writing Query Expressions
  • Can be combined with any of the other LINQ
    technologies
  • Supports SAX-style reading/writing of documents
    with the use of XStreamingElement
  • Differed execution

11
LINQ to XML
  • Combining it with other LINQ technologies makes
    life easier

XElement xml new XElement("contacts", new
XElement("contact", new XAttribute("contactId"
, "2"), new XElement("firstName",
"Barry"), new XElement("lastName",
"Gottshall") ), new XElement("contact", new
XAttribute("contactId", "3"), new
XElement("firstName", "Armando"), new
XElement("lastName", "Valdes") ) )
12
LINQ to XML
  • Result from previous example

ltcontactsgt ltcontact contactId"2"gt
ltfirstNamegtBarrylt/firstNamegt
ltlastNamegtGottshalllt/lastNamegt lt/contactgt
ltcontact contactId"3"gt ltfirstNamegtArmandolt/fi
rstNamegt ltlastNamegtValdeslt/lastNamegt
lt/contactgt lt/contactsgt
13
LINQ to DataSet(s)
  • Allows developers to query existing DataSet
    sources within applications
  • Offline, still uses IQueryableltTgt approach
  • 2 types of queries, depending on use of
    typed/un-typed datasets
  • Use LINQ in current applications without
    re-writing using LINQ to SQL
  • Bi-directional LINQ Sequence -gt DataTable -gt
    LINQ Sequence support

14
How Does it Work?
  • Depends on if the type is 0 or not
  • IQueryableltTgt
  • System.Linq.Queryable (System.Data.Linq.DataQuerylt
    Tgt)
  • SQL
  • Entity
  • Datasets
  • The extension methods build an expression tree
  • If not, then check if it is a IEnumerableltTgt
  • System.Linq.IEnumerableltTgt
  • Objects
  • XML
  • The extension methods run the query

15
How Does it Work?
C 3.0
VB 9.0
Others
.NET Language Integrated Query
LINQ toObjects
LINQ toSQL
LINQ toXML
LINQ toEntities
LINQ toDatasets
16
How Does it Work?
  • Extension methods for the from/select/where/groupb
    y keywords
  • Lambda expressions
  • Expression tree for building pre-compiling the
    statement that will run on a IQueryableltTgt
  • pgt p.CompanyName.StartsWith(A)
  • Iterators for the in-memory queries
    (IEnumerableltTgt)
  • foreach on an IEnumerableltTgt

17
Whats Next?
  • PLINQ
  • Parallel FX Library
  • IParallelEnumerableltTgt
  • CTP is available
  • Support for 3rd party DB engines
Write a Comment
User Comments (0)
About PowerShow.com