Introducing LINQ     Learn More @ http://www.learnnowonline.com        Copyright © by Application Developers Training Comp...
Objectives         Learn More @ http://www.learnnowonline.com             Copyright © by Application Developers Training C...
Objectives• Motivate the need for LINQ            Learn More @ http://www.learnnowonline.com               Copyright © by ...
Objectives• Motivate the need for LINQ• Learn about the various LINQ providers             Learn More @ http://www.learnno...
Objectives• Motivate the need for LINQ• Learn about the various LINQ providers• Investigate simple LINQ to Objects, LINQ t...
Agenda         Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers Training Company
Agenda• Language Integrated Query          Learn More @ http://www.learnnowonline.com             Copyright © by Applicati...
Agenda• Language Integrated Query• Structure of a LINQ Query          Learn More @ http://www.learnnowonline.com          ...
Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples          Learn More @ http://www.learnnow...
Language Integrated Query        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developer...
Language Integrated Query• Querying and manipulating data has always  been a fundamental part of our jobs as  developers  ...
Language Integrated Query• Querying and manipulating data has always  been a fundamental part of our jobs as  developers• ...
Language Integrated Query• Querying and manipulating data has always  been a fundamental part of our jobs as  developers• ...
Data Access(DBASE, 1985 or so)            Learn More @ http://www.learnnowonline.com               Copyright © by Applicat...
Data Access(DBASE, 1985 or so)     USE empl     REPLACE ALL salary WITH (salary * 1.1)     FOR supervises > 0     LIST ALL...
Data Access APIs (C#)(late 1990s/early 2000s)             Learn More @ http://www.learnnowonline.com                Copyri...
Data Access APIs (C#)(late 1990s/early 2000s)      SqlCommand cmd = new SqlCommand(        @"SELECT fname, lname, salary  ...
Object/Relational Mapping (C#)(last few years)              Learn More @ http://www.learnnowonline.com                   C...
Object/Relational Mapping (C#)(last few years)   public class Employee   {     public string FirstName;     public string ...
Data Access APIs (VB)(late 1990s/early 2000s)             Learn More @ http://www.learnnowonline.com                Copyri...
Data Access APIs (VB)(late 1990s/early 2000s)   Dim cmd As New SqlCommand( _     "SELECT fname, lname, salary" & _     " F...
Object/Relational Mapping (VB)(last few years)             Learn More @ http://www.learnnowonline.com                   Co...
Object/Relational Mapping (VB)(last few years)   Public Class Employee     Public FirstName As String     Public LastName ...
Object/Relational Mapping         Learn More @ http://www.learnnowonline.com            Copyright © by Application Develop...
Object/Relational Mapping• Provides:              Learn More @ http://www.learnnowonline.com                 Copyright © b...
Object/Relational Mapping• Provides:   Mapping between relational data to/from objects              Learn More @ http://w...
Object/Relational Mapping• Provides:   Mapping between relational data to/from objects   Cleaner integration of business...
LINQ to the Rescue      Learn More @ http://www.learnnowonline.com         Copyright © by Application Developers Training ...
LINQ to the Rescue• How do you retrieve non-relational data?          Learn More @ http://www.learnnowonline.com          ...
LINQ to the Rescue• How do you retrieve non-relational data?   XML, RSS, Web Services, REST, AD, Files, and so on        ...
LINQ to the Rescue• How do you retrieve non-relational data?   XML, RSS, Web Services, REST, AD, Files, and so on• How do...
LINQ to the Rescue• How do you retrieve non-relational data?   XML, RSS, Web Services, REST, AD, Files, and so on• How do...
LINQ to the Rescue• How do you retrieve non-relational data?   XML, RSS, Web Services, REST, AD, Files, and so on• How do...
LINQ       Learn More @ http://www.learnnowonline.com          Copyright © by Application Developers Training Company
LINQ• Query, Set, and Transform Operations for .NET             Learn More @ http://www.learnnowonline.com                ...
LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming  concept             Learn Mor...
LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming  concept• Works with all types...
LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming  concept• Works with all types...
LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming  concept• Works with all types...
LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming  concept• Works with all types...
LINQ       Learn More @ http://www.learnnowonline.com          Copyright © by Application Developers Training Company
LINQ• Works with all .NET languages            Learn More @ http://www.learnnowonline.com               Copyright © by App...
LINQ• Works with all .NET languages   VB and C# have integrated language support             Learn More @ http://www.lear...
LINQ• Works with all .NET languages   VB and C# have integrated language support• Works in any kind of project including ...
LINQ• Works with all .NET languages   VB and C# have integrated language support• Works in any kind of project including ...
LINQ• Works with all .NET languages   VB and C# have integrated language support• Works in any kind of project including ...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• C# uses LINQ providers to map your LINQ  queries to the data source that you’re querying             Learn...
LINQ Providers• C# uses LINQ providers to map your LINQ  queries to the data source that you’re querying• The LINQ provide...
LINQ Providers• C# uses LINQ providers to map your LINQ  queries to the data source that you’re querying• The LINQ provide...
LINQ Overview        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training C...
LINQ Overview              LINQ enabled data sources        Learn More @ http://www.learnnowonline.com           Copyright...
LINQ Overview                    LINQ enabled data sources    LINQ To Objects  Objects              Learn More @ http://ww...
LINQ Overview                    LINQ enabled data sources                      LINQ enabled ADO.NET    LINQ         LINQ ...
LINQ Overview                    LINQ enabled data sources                      LINQ enabled ADO.NET    LINQ         LINQ ...
LINQ Overview      VB                                 C#                               Others…                .NET Languag...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• LINQ to Objects            Learn More @ http://www.learnnowonline.com               Copyright © by Applica...
LINQ Providers• LINQ to Objects   Allows you to query in-memory of sets of objects              Learn More @ http://www.l...
LINQ Providers• LINQ to Objects   Allows you to query in-memory of sets of objects     o   Collections, arrays, and lists...
LINQ Providers• LINQ to Objects   Allows you to query in-memory of sets of objects     o   Collections, arrays, and lists...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• LINQ to SQL           Learn More @ http://www.learnnowonline.com                Copyright © by Application...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server             Learn More @ http://www.learn...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers• LINQ to SQL   Allows you to query and modify data in SQL Server   You provide mapping between a modeling...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• LINQ to XML           Learn More @ http://www.learnnowonline.com                Copyright © by Application...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content             Learn More @ http://www.learnno...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content   Can work with XML from file, or from str...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content   Can work with XML from file, or from str...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content   Can work with XML from file, or from str...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content   Can work with XML from file, or from str...
LINQ Providers• LINQ to XML   Easy to query, modify, and generate XML content   Can work with XML from file, or from str...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• LINQ to DataSet            Learn More @ http://www.learnnowonline.com               Copyright © by Applica...
LINQ Providers• LINQ to DataSet   Allows you to query and update data in ADO.NET    dataset             Learn More @ http...
LINQ Providers• LINQ to DataSet   Allows you to query and update data in ADO.NET    dataset   Can use querying engine ag...
LINQ Providers• LINQ to DataSet   Allows you to query and update data in ADO.NET    dataset   Can use querying engine ag...
LINQ Providers• LINQ to DataSet   Allows you to query and update data in ADO.NET    dataset   Can use querying engine ag...
LINQ Providers• LINQ to DataSet   Allows you to query and update data in ADO.NET    dataset   Can use querying engine ag...
LINQ Providers        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training ...
LINQ Providers• LINQ to Entities             Learn More @ http://www.learnnowonline.com                Copyright © by Appl...
LINQ Providers• LINQ to Entities   Allows developers to query data exposed using Entity    Data Model (EDM)              ...
LINQ Providers• LINQ to Entities   Allows developers to query data exposed using Entity    Data Model (EDM)     o   EDM: ...
LINQ Providers• LINQ to Entities   Allows developers to query data exposed using Entity    Data Model (EDM)     o   EDM: ...
LINQ Providers• LINQ to Entities   Allows developers to query data exposed using Entity    Data Model (EDM)     o   EDM: ...
LINQ Providers• LINQ to Entities   Allows developers to query data exposed using Entity    Data Model (EDM)     o   EDM: ...
Agenda         Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers Training Company
Agenda• Language Integrated Query            Learn More @ http://www.learnnowonline.com               Copyright © by Appli...
Agenda• Language Integrated Query• Structure of a LINQ Query           Learn More @ http://www.learnnowonline.com         ...
Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples           Learn More @ http://www.learnno...
Structure of a LINQ Query         Learn More @ http://www.learnnowonline.com            Copyright © by Application Develop...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables             Lear...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
Structure of a LINQ Query• LINQ query contains clauses that specify data  sources and iteration variables• Query expressio...
The Three Stages of a LINQ Query        Learn More @ http://www.learnnowonline.com           Copyright © by Application De...
The Three Stages of a LINQ Query• Each LINQ query requires three stages:            Learn More @ http://www.learnnowonline...
The Three Stages of a LINQ Query• Each LINQ query requires three stages:   Obtain the data source(s)              Learn M...
The Three Stages of a LINQ Query• Each LINQ query requires three stages:   Obtain the data source(s)   Create the query ...
The Three Stages of a LINQ Query• Each LINQ query requires three stages:   Obtain the data source(s)   Create the query ...
The Data Source        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training...
The Data Source• In the sample, data source is an array of  integers             Learn More @ http://www.learnnowonline.co...
The Data Source• In the sample, data source is an array of  integers• Because array implements IEnumerable, can  query aga...
The Data Source• In the sample, data source is an array of  integers• Because array implements IEnumerable, can  query aga...
XML as Data Source (VB) VBDim items As XElement = XElement.Load("C:Grocery.xml")               Learn More @ http://www.lea...
XML as Data Source (VB)• Could use LINQ to XML to load contents of an  XML file into a queryable collection of XElement  i...
XML as Data Source (C#)// C#:XElement items = XElement.Load(@"C:Grocery.xml");               Learn More @ http://www.learn...
XML as Data Source (C#)• Could use LINQ to XML to load contents of an  XML file into a queryable collection of XElement  i...
SQL as Data Source (VB) VBDim dc As New DataContext( _  My.Settings.NorthwindConnectionString)Dim customers As Table(Of Cu...
SQL as Data Source (VB)• Can use LINQ to SQL once you have a class that  provides object-relational mapping:  VB Dim dc As...
SQL as Data Source (C#) // C# DataContext dc = new DataContext(  Properties.Settings.Default.NorthwindConnectionString); T...
SQL as Data Source (C#)• Can use LINQ to SQL once you have a class that  provides object-relational mapping:  // C#  DataC...
The Query        Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers Training Comp...
The Query• Given the data source, can specify the query             Learn More @ http://www.learnnowonline.com            ...
The Query• Given the data source, can specify the query   Defines the information you want to retrieve              Learn...
The Query• Given the data source, can specify the query   Defines the information you want to retrieve   Optionally, can...
The Query• Given the data source, can specify the query   Defines the information you want to retrieve   Optionally, can...
The Query Execution        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Trai...
The Query Execution• Query definition doesnt execute the query             Learn More @ http://www.learnnowonline.com     ...
The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its  time to...
The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its  time to...
The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its  time to...
Returning Multiple Values         Learn More @ http://www.learnnowonline.com            Copyright © by Application Develop...
Returning Multiple Values• Want to return multiple values?             Learn More @ http://www.learnnowonline.com         ...
Returning Multiple Values• Want to return multiple values?• In general, two options:             Learn More @ http://www.l...
Returning Multiple Values• Want to return multiple values?• In general, two options:   Create class that exposes properti...
Returning Multiple Values• Want to return multiple values?• In general, two options:   Create class that exposes properti...
Returning Multiple Values• Want to return multiple values?• In general, two options:   Create class that exposes properti...
Returning Multiple Values• Want to return multiple values?• In general, two options:   Create class that exposes properti...
Creating a Class for Return Values         Learn More @ http://www.learnnowonline.com            Copyright © by Applicatio...
Creating a Class for Return Values• See MyFileInfo class and MultipleReturnValues1             Learn More @ http://www.lea...
Using an Anonymous Type        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers ...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)             Learn More @ http://www...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Using an Anonymous Type• In previous example, code created a simple type  (MyFileInfo)   Type contained properties return...
Deferred Execution        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Train...
Deferred Execution• Defining query doesnt cause query to execute             Learn More @ http://www.learnnowonline.com   ...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data        ...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In oth...
Converting Results to Force Execution          Learn More @ http://www.learnnowonline.com             Copyright © by Appli...
Converting Results to Force Execution• Sometimes, might want to immediately execute  query and cache its results          ...
Converting Results to Force Execution• Sometimes, might want to immediately execute  query and cache its results• Can use ...
Converting Results to Force Execution• Sometimes, might want to immediately execute  query and cache its results• Can use ...
Agenda         Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers Training Company
Agenda• Language Integrated Query            Learn More @ http://www.learnnowonline.com               Copyright © by Appli...
Agenda• Language Integrated Query• Structure of a LINQ Query            Learn More @ http://www.learnnowonline.com        ...
Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples            Learn More @ http://www.learnn...
Some LINQ Examples       Learn More @ http://www.learnnowonline.com          Copyright © by Application Developers Trainin...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ             Learn More @ http://www.learnnowo...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ• Introduce some of the new language features ...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ• Introduce some of the new language features ...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ• Introduce some of the new language features ...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ• Introduce some of the new language features ...
Some LINQ Examples• Get a taste of the kinds of things you can do  with LINQ• Introduce some of the new language features ...
LINQ to Objects        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training...
LINQ to Objects• Can use any collection that implements  IEnumerable (or generic version) as data source             Learn...
LINQ to Objects• Can use any collection that implements  IEnumerable (or generic version) as data source• Note example use...
Query Syntax/Extension Methods(C#)         Learn More @ http://www.learnnowonline.com            Copyright © by Applicatio...
Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like  select, where, and orderby into executa...
Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like  select, where, and orderby into executa...
Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like  select, where, and orderby into executa...
Query Syntax/Extension Methods(VB)        Learn More @ http://www.learnnowonline.com           Copyright © by Application ...
Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like  Select, Where, and Order By into execut...
Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like  Select, Where, and Order By into execut...
Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like  Select, Where, and Order By into execut...
Continuing the Investigation         Learn More @ http://www.learnnowonline.com            Copyright © by Application Deve...
Continuing the Investigation• So compiler converts keywords into methods            Learn More @ http://www.learnnowonline...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface            L...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface   It doesnt...
Extension Methods (VB)        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers T...
Extension Methods (VB)• Add new methods to existing classes            Learn More @ http://www.learnnowonline.com         ...
Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ             Learn Mor...
Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (C#)        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers T...
Extension Methods (C#)• Add new methods to existing classes            Learn More @ http://www.learnnowonline.com         ...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ             Learn Mor...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods mu...
Using LINQ to Group Output        Learn More @ http://www.learnnowonline.com           Copyright © by Application Develope...
Using LINQ to Group Output• System.Linq.Enumerable class provides large  number of methods            Learn More @ http://...
Using LINQ to Group Output• System.Linq.Enumerable class provides large  number of methods• Look for grouping methods     ...
LINQ to SQL        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training Com...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases             Learn More @ http:...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET           ...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
LINQ to SQL• Allows standard LINQ queries to work with data  stored in relational databases    Extends ADO.NET    Adds s...
Linking a Class to SQL Server         Learn More @ http://www.learnnowonline.com            Copyright © by Application Dev...
Linking a Class to SQL Server• Retrieve data from Northwind Customers table            Learn More @ http://www.learnnowonl...
Linking a Class to SQL Server• Retrieve data from Northwind Customers table• Retrieve CustomerID, CompanyName,  ContactNam...
Linking a Class to SQL Server• Retrieve data from Northwind Customers table• Retrieve CustomerID, CompanyName,  ContactNam...
Creating the Class         Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers Tra...
Creating the Class• Start by creating a class with properties that  correspond to columns in the database             Lear...
Creating the Class• Start by creating a class with properties that  correspond to columns in the database• See Customer1 c...
Marking Up the Class        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Tra...
Marking Up the Class• Use attributes from the  System.Data.Linq.Mapping namespace           Learn More @ http://www.learnn...
Marking Up the Class• Use attributes from the  System.Data.Linq.Mapping namespace   Table            Learn More @ http://...
Marking Up the Class• Use attributes from the  System.Data.Linq.Mapping namespace   Table   Column             Learn Mor...
Marking Up the Class• Use attributes from the  System.Data.Linq.Mapping namespace   Table   Column   Many others       ...
Marking Up the Class• Use attributes from the  System.Data.Linq.Mapping namespace   Table   Column   Many others• See C...
Retrieving a Collection of Customers          Learn More @ http://www.learnnowonline.com             Copyright © by Applic...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data           Learn Mor...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Retrieving a Collection of Customers• Need some mechanism to manage connection  between class and data   Cant simply fill...
Determining the Actual SQL String         Learn More @ http://www.learnnowonline.com            Copyright © by Application...
Determining the Actual SQL String• Set Log property of DataContext to stream            Learn More @ http://www.learnnowon...
Determining the Actual SQL String• Set Log property of DataContext to stream   Sends all information to the output stream...
Determining the Actual SQL String• Set Log property of DataContext to stream   Sends all information to the output stream...
Determining the Actual SQL String• Set Log property of DataContext to stream   Sends all information to the output stream...
Working with Anonymous Types        Learn More @ http://www.learnnowonline.com           Copyright © by Application Develo...
Working with Anonymous Types• Anonymous types work well with LINQ to SQL            Learn More @ http://www.learnnowonline...
Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns ...
Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns ...
Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns ...
LINQ to XML        Learn More @ http://www.learnnowonline.com           Copyright © by Application Developers Training Com...
LINQ to XML• Need to retrieve, create, query XML?             Learn More @ http://www.learnnowonline.com                Co...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support            Learn More @ http://www...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex           ...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support   Steps can be complex   Can req...
Life without LINQ to XML         Learn More @ http://www.learnnowonline.com            Copyright © by Application Develope...
Life without LINQ to XML• Without LINQ to XML, creating XML content  required multiple steps            Learn More @ http:...
Life without LINQ to XML• Without LINQ to XML, creating XML content  required multiple steps   XmlDocument creates new el...
Life without LINQ to XML• Without LINQ to XML, creating XML content  required multiple steps   XmlDocument creates new el...
Life without LINQ to XML• Without LINQ to XML, creating XML content  required multiple steps   XmlDocument creates new el...
Life without LINQ to XML• Without LINQ to XML, creating XML content  required multiple steps   XmlDocument creates new el...
Using System.Xml.Linq Classes        Learn More @ http://www.learnnowonline.com           Copyright © by Application Devel...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes            Learn More @ http://www.learnnowonline.co...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment             Learn ...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment   All inherit fro...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment   All inherit fro...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment   All inherit fro...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment   All inherit fro...
Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes   XElement, XAttribute, XComment   All inherit fro...
Creating Data: From and Select         Learn More @ http://www.learnnowonline.com            Copyright © by Application De...
Creating Data: From and Select• From clause sets up range variable iterating  over data source             Learn More @ ht...
Creating Data: From and Select• From clause sets up range variable iterating  over data source• Select clause specifies "s...
Creating Data: From and Select• From clause sets up range variable iterating  over data source• Select clause specifies "s...
Creating Data: From and Select• From clause sets up range variable iterating  over data source• Select clause specifies "s...
Visual Basic Only (VB)         Learn More @ http://www.learnnowonline.com            Copyright © by Application Developers...
Visual Basic Only (VB)• Only Visual Basic adds new features that make  it far easier to work with LINQ to XML             ...
Visual Basic Only (VB)• Only Visual Basic adds new features that make  it far easier to work with LINQ to XML   XML liter...
Visual Basic Only (VB)• Only Visual Basic adds new features that make  it far easier to work with LINQ to XML   XML liter...
Visual Basic Only (VB)• Only Visual Basic adds new features that make  it far easier to work with LINQ to XML   XML liter...
Learn More!       Learn More @ http://www.learnnowonline.com          Copyright © by Application Developers Training Company
Learn More!• This is an excerpt from a larger course. Visit  www.learnnowonline.com for the full details!           Learn ...
Upcoming SlideShare
Loading in …5
×

Introducing LINQ

1,634 views

Published on

Learn about LINQ, its providers, and investigate simple LINQ to Objects, LINQ to SQL, and LINQ to XML samples.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,634
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: May want to investigate the sample, NumbersGreaterThan5\n
  • DEMO: May want to investigate the sample, NumbersGreaterThan5\n
  • DEMO: May want to investigate the sample, NumbersGreaterThan5\n
  • DEMO: May want to investigate the sample, NumbersGreaterThan5\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: May want to investigate NumbersGreaterThan5 query\n
  • DEMO: May want to investigate NumbersGreaterThan5 query\n
  • DEMO: May want to investigate NumbersGreaterThan5 query\n
  • DEMO: May want to investigate NumbersGreaterThan5 query\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to work with anonymous type\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to demo the following:\nDeferredExecution and DoubleIt procedures\nDeferredExecution1\n
  • DEMO: May want to try ForcingExecution\n
  • DEMO: May want to try ForcingExecution\n
  • DEMO: May want to try ForcingExecution\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: May want to demo the following:\nNumberQuery0\nNumberQuery1\nNumberQueryTheOldWay\n
  • DEMO: May want to demo the following:\nNumberQuery0\nNumberQuery1\nNumberQueryTheOldWay\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • DEMO: May want to look in ILDASM for disassembled output\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine the following:\nExtensions\nNumberQueryWithExtensionMethod\n
  • DEMO: May want to examine NumbersGrouping\n
  • DEMO: May want to examine NumbersGrouping\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • DEMO: rest of section\n
  • Introducing LINQ

    1. 1. Introducing LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    2. 2. Objectives Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    3. 3. Objectives• Motivate the need for LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    4. 4. Objectives• Motivate the need for LINQ• Learn about the various LINQ providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    5. 5. Objectives• Motivate the need for LINQ• Learn about the various LINQ providers• Investigate simple LINQ to Objects, LINQ to SQL, and LINQ to XML samples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    6. 6. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    7. 7. Agenda• Language Integrated Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    8. 8. Agenda• Language Integrated Query• Structure of a LINQ Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    9. 9. Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    10. 10. Language Integrated Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    11. 11. Language Integrated Query• Querying and manipulating data has always been a fundamental part of our jobs as developers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    12. 12. Language Integrated Query• Querying and manipulating data has always been a fundamental part of our jobs as developers• Data formats change, but core needs are the same Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    13. 13. Language Integrated Query• Querying and manipulating data has always been a fundamental part of our jobs as developers• Data formats change, but core needs are the same  Must create, retrieve, update, and delete data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    14. 14. Data Access(DBASE, 1985 or so) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    15. 15. Data Access(DBASE, 1985 or so) USE empl REPLACE ALL salary WITH (salary * 1.1) FOR supervises > 0 LIST ALL fname, lname, salary FOR Supervises > 0 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    16. 16. Data Access APIs (C#)(late 1990s/early 2000s) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    17. 17. Data Access APIs (C#)(late 1990s/early 2000s) SqlCommand cmd = new SqlCommand( @"SELECT fname, lname, salary FROM Empl WHERE supervises > @p0" ); cmd.Parameters.AddWithValue("@po", 0); SqlConnection c = new SqlConnection(…); c.Open(); DataReader people = c.Execute(cmd); while (people.Read()) { string fname = (string) people["fname"]; string lname = (string) people["lname"]; double salary = (double) people["salary"]; } people.Close(); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    18. 18. Object/Relational Mapping (C#)(last few years) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    19. 19. Object/Relational Mapping (C#)(last few years) public class Employee { public string FirstName; public string LastName; public double Salary; } IList employees = session.CreateCriteria(typeof(Employee)) .Add(Expression.Gt("supervises", 0) .List(); foreach(Employee employee in employees) { string fname = employee.FirstName; string lname = employee.LastName; double salary = employee.Salary; } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    20. 20. Data Access APIs (VB)(late 1990s/early 2000s) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    21. 21. Data Access APIs (VB)(late 1990s/early 2000s) Dim cmd As New SqlCommand( _ "SELECT fname, lname, salary" & _ " FROM Empl" & _ " WHERE supervises > @p0") cmd.Parameters.AddWithValue("@p0", 0) Dim cnn as New SqlConnection(…) cnn.Open() Dim people As DataReader = cnn.Execute(cmd) While people.Read() Dim fname As String = people("fname").ToString() Dim lname As String = people("lname").ToString() Dim salary As Double = CDbl(people("salary")) End While people.Close(); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    22. 22. Object/Relational Mapping (VB)(last few years) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    23. 23. Object/Relational Mapping (VB)(last few years) Public Class Employee Public FirstName As String Public LastName As String Public Salary As Double End Class Dim employees As IList = _ session.CreateCriteria(GetType(Employee). _ Add(Expression.Gt("supervises", 0).List() For Each employee As Employee In Employees Dim fname As String = people("fname").ToString() Dim lname As String = people("lname").ToString() Dim salary As Double = CDbl(people("salary")) Next employee Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    24. 24. Object/Relational Mapping Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    25. 25. Object/Relational Mapping• Provides: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    26. 26. Object/Relational Mapping• Provides:  Mapping between relational data to/from objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    27. 27. Object/Relational Mapping• Provides:  Mapping between relational data to/from objects  Cleaner integration of business rules and validation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    28. 28. LINQ to the Rescue Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    29. 29. LINQ to the Rescue• How do you retrieve non-relational data? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    30. 30. LINQ to the Rescue• How do you retrieve non-relational data?  XML, RSS, Web Services, REST, AD, Files, and so on Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    31. 31. LINQ to the Rescue• How do you retrieve non-relational data?  XML, RSS, Web Services, REST, AD, Files, and so on• How do you interact with plain old objects? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    32. 32. LINQ to the Rescue• How do you retrieve non-relational data?  XML, RSS, Web Services, REST, AD, Files, and so on• How do you interact with plain old objects?  How do you interact and query custom domain models? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    33. 33. LINQ to the Rescue• How do you retrieve non-relational data?  XML, RSS, Web Services, REST, AD, Files, and so on• How do you interact with plain old objects?  How do you interact and query custom domain models?• How do you enable clean code in both a strongly typed and dynamic language world? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    34. 34. LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    35. 35. LINQ• Query, Set, and Transform Operations for .NET Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    36. 36. LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming concept Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    37. 37. LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming concept• Works with all types and shapes of data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    38. 38. LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming concept• Works with all types and shapes of data  Relational databases Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    39. 39. LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming concept• Works with all types and shapes of data  Relational databases  XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    40. 40. LINQ• Query, Set, and Transform Operations for .NET• Makes querying data a core programming concept• Works with all types and shapes of data  Relational databases  XML  Plain old objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    41. 41. LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    42. 42. LINQ• Works with all .NET languages Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    43. 43. LINQ• Works with all .NET languages  VB and C# have integrated language support Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    44. 44. LINQ• Works with all .NET languages  VB and C# have integrated language support• Works in any kind of project including Windows and Web projects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    45. 45. LINQ• Works with all .NET languages  VB and C# have integrated language support• Works in any kind of project including Windows and Web projects• Also can find third party LINQ providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    46. 46. LINQ• Works with all .NET languages  VB and C# have integrated language support• Works in any kind of project including Windows and Web projects• Also can find third party LINQ providers  Amazon.com for example Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    47. 47. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    48. 48. LINQ Providers• C# uses LINQ providers to map your LINQ queries to the data source that you’re querying Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    49. 49. LINQ Providers• C# uses LINQ providers to map your LINQ queries to the data source that you’re querying• The LINQ provider takes the query that you create in code, and converts it into commands that the data source will be able to execute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    50. 50. LINQ Providers• C# uses LINQ providers to map your LINQ queries to the data source that you’re querying• The LINQ provider takes the query that you create in code, and converts it into commands that the data source will be able to execute• On return from executing the commands, the provider also converts the data into objects that create your query results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    51. 51. LINQ Overview Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    52. 52. LINQ Overview LINQ enabled data sources Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    53. 53. LINQ Overview LINQ enabled data sources LINQ To Objects Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    54. 54. LINQ Overview LINQ enabled data sources LINQ enabled ADO.NET LINQ LINQ LINQ LINQ To Objects To Datasets To SQL To Entities Objects Relational Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    55. 55. LINQ Overview LINQ enabled data sources LINQ enabled ADO.NET LINQ LINQ LINQ LINQ LINQ To Objects To Datasets To SQL To Entities To XML <book> <title/> <author/> <price/ > </book> Objects Relational XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    56. 56. LINQ Overview VB C# Others… .NET Language-Integrated Query LINQ enabled data sources LINQ enabled ADO.NET LINQ LINQ LINQ LINQ LINQ To Objects To Datasets To SQL To Entities To XML <book> <title/> <author/> <price/ > </book> Objects Relational XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    57. 57. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    58. 58. LINQ Providers• LINQ to Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    59. 59. LINQ Providers• LINQ to Objects  Allows you to query in-memory of sets of objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    60. 60. LINQ Providers• LINQ to Objects  Allows you to query in-memory of sets of objects o Collections, arrays, and lists Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    61. 61. LINQ Providers• LINQ to Objects  Allows you to query in-memory of sets of objects o Collections, arrays, and lists o If a class implements IEnumerable (or generic version), you can use LINQ to query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    62. 62. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    63. 63. LINQ Providers• LINQ to SQL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    64. 64. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    65. 65. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    66. 66. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source  Use System.Data.Linq.DataContext class to provide the “plumbing” Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    67. 67. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source  Use System.Data.Linq.DataContext class to provide the “plumbing”  Can use Visual Studio’s O/R designer to make it easy Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    68. 68. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source  Use System.Data.Linq.DataContext class to provide the “plumbing”  Can use Visual Studio’s O/R designer to make it easy o For now, will mark up entity class manually Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    69. 69. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source  Use System.Data.Linq.DataContext class to provide the “plumbing”  Can use Visual Studio’s O/R designer to make it easy o For now, will mark up entity class manually  DataContext manages communication Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    70. 70. LINQ Providers• LINQ to SQL  Allows you to query and modify data in SQL Server  You provide mapping between a modeling class and schema in data source  Use System.Data.Linq.DataContext class to provide the “plumbing”  Can use Visual Studio’s O/R designer to make it easy o For now, will mark up entity class manually  DataContext manages communication o Stores state for optimistic concurrency checks Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    71. 71. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    72. 72. LINQ Providers• LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    73. 73. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    74. 74. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content  Can work with XML from file, or from stream Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    75. 75. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content  Can work with XML from file, or from stream  System.Linq.Xml.XObject, Xnode, XElement, XAttribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    76. 76. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content  Can work with XML from file, or from stream  System.Linq.Xml.XObject, Xnode, XElement, XAttribute o Make it easy to work with XML programmatically Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    77. 77. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content  Can work with XML from file, or from stream  System.Linq.Xml.XObject, Xnode, XElement, XAttribute o Make it easy to work with XML programmatically  LINQ to XML provider works with these classes to create queryable collections of XML data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    78. 78. LINQ Providers• LINQ to XML  Easy to query, modify, and generate XML content  Can work with XML from file, or from stream  System.Linq.Xml.XObject, Xnode, XElement, XAttribute o Make it easy to work with XML programmatically  LINQ to XML provider works with these classes to create queryable collections of XML data  Visual Basic adds language-specific rich support for LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    79. 79. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    80. 80. LINQ Providers• LINQ to DataSet Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    81. 81. LINQ Providers• LINQ to DataSet  Allows you to query and update data in ADO.NET dataset Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    82. 82. LINQ Providers• LINQ to DataSet  Allows you to query and update data in ADO.NET dataset  Can use querying engine against data already cached in client application Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    83. 83. LINQ Providers• LINQ to DataSet  Allows you to query and update data in ADO.NET dataset  Can use querying engine against data already cached in client application  Strongly typed datasets easier to work with than standard datasets Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    84. 84. LINQ Providers• LINQ to DataSet  Allows you to query and update data in ADO.NET dataset  Can use querying engine against data already cached in client application  Strongly typed datasets easier to work with than standard datasets o You already know the schema—its just LINQ to Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    85. 85. LINQ Providers• LINQ to DataSet  Allows you to query and update data in ADO.NET dataset  Can use querying engine against data already cached in client application  Strongly typed datasets easier to work with than standard datasets o You already know the schema—its just LINQ to Objects  Language features make it possible to query standard datasets Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    86. 86. LINQ Providers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    87. 87. LINQ Providers• LINQ to Entities Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    88. 88. LINQ Providers• LINQ to Entities  Allows developers to query data exposed using Entity Data Model (EDM) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    89. 89. LINQ Providers• LINQ to Entities  Allows developers to query data exposed using Entity Data Model (EDM) o EDM: conceptual model, allows applications to interact with data as if it was a collection of objects, or entities Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    90. 90. LINQ Providers• LINQ to Entities  Allows developers to query data exposed using Entity Data Model (EDM) o EDM: conceptual model, allows applications to interact with data as if it was a collection of objects, or entities  Using EDM, ADO.NET exposes entities as objects in .NET Framework, allows LINQ queries to operate Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    91. 91. LINQ Providers• LINQ to Entities  Allows developers to query data exposed using Entity Data Model (EDM) o EDM: conceptual model, allows applications to interact with data as if it was a collection of objects, or entities  Using EDM, ADO.NET exposes entities as objects in .NET Framework, allows LINQ queries to operate  Conceptually, same as LINQ to SQL, but works with any data source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    92. 92. LINQ Providers• LINQ to Entities  Allows developers to query data exposed using Entity Data Model (EDM) o EDM: conceptual model, allows applications to interact with data as if it was a collection of objects, or entities  Using EDM, ADO.NET exposes entities as objects in .NET Framework, allows LINQ queries to operate  Conceptually, same as LINQ to SQL, but works with any data source o Doesnt assume one-to-one mapping between classes and schema Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    93. 93. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    94. 94. Agenda• Language Integrated Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    95. 95. Agenda• Language Integrated Query• Structure of a LINQ Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    96. 96. Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    97. 97. Structure of a LINQ Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    98. 98. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    99. 99. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    100. 100. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    101. 101. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering  Sorting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    102. 102. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering  Sorting  Grouping Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    103. 103. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering  Sorting  Grouping  Joining Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    104. 104. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering  Sorting  Grouping  Joining  Calculating Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    105. 105. Structure of a LINQ Query• LINQ query contains clauses that specify data sources and iteration variables• Query expressions can also include:  Filtering  Sorting  Grouping  Joining  Calculating• From required—indicates source of data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    106. 106. The Three Stages of a LINQ Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    107. 107. The Three Stages of a LINQ Query• Each LINQ query requires three stages: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    108. 108. The Three Stages of a LINQ Query• Each LINQ query requires three stages:  Obtain the data source(s) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    109. 109. The Three Stages of a LINQ Query• Each LINQ query requires three stages:  Obtain the data source(s)  Create the query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    110. 110. The Three Stages of a LINQ Query• Each LINQ query requires three stages:  Obtain the data source(s)  Create the query  Execute the query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    111. 111. The Data Source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    112. 112. The Data Source• In the sample, data source is an array of integers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    113. 113. The Data Source• In the sample, data source is an array of integers• Because array implements IEnumerable, can query against it Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    114. 114. The Data Source• In the sample, data source is an array of integers• Because array implements IEnumerable, can query against it  Treated as a "queryable" type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    115. 115. XML as Data Source (VB) VBDim items As XElement = XElement.Load("C:Grocery.xml") Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    116. 116. XML as Data Source (VB)• Could use LINQ to XML to load contents of an XML file into a queryable collection of XElement instances: VB Dim items As XElement = XElement.Load("C:Grocery.xml") Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    117. 117. XML as Data Source (C#)// C#:XElement items = XElement.Load(@"C:Grocery.xml"); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    118. 118. XML as Data Source (C#)• Could use LINQ to XML to load contents of an XML file into a queryable collection of XElement instances: // C#: XElement items = XElement.Load(@"C:Grocery.xml"); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    119. 119. SQL as Data Source (VB) VBDim dc As New DataContext( _ My.Settings.NorthwindConnectionString)Dim customers As Table(Of Customer) = _ dc.GetTable(Of Customer) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    120. 120. SQL as Data Source (VB)• Can use LINQ to SQL once you have a class that provides object-relational mapping: VB Dim dc As New DataContext( _ My.Settings.NorthwindConnectionString) Dim customers As Table(Of Customer) = _ dc.GetTable(Of Customer) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    121. 121. SQL as Data Source (C#) // C# DataContext dc = new DataContext( Properties.Settings.Default.NorthwindConnectionString); Table<Customer> customers = dc.GetTable<Customer>(); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    122. 122. SQL as Data Source (C#)• Can use LINQ to SQL once you have a class that provides object-relational mapping: // C# DataContext dc = new DataContext( Properties.Settings.Default.NorthwindConnectionString); Table<Customer> customers = dc.GetTable<Customer>(); Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    123. 123. The Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    124. 124. The Query• Given the data source, can specify the query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    125. 125. The Query• Given the data source, can specify the query  Defines the information you want to retrieve Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    126. 126. The Query• Given the data source, can specify the query  Defines the information you want to retrieve  Optionally, can specify how to sort, filter, and group Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    127. 127. The Query• Given the data source, can specify the query  Defines the information you want to retrieve  Optionally, can specify how to sort, filter, and group• LINQ queries are generally the same, no matter the data source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    128. 128. The Query Execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    129. 129. The Query Execution• Query definition doesnt execute the query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    130. 130. The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its time to retrieve the data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    131. 131. The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its time to retrieve the data• To execute, need to run code that forces query reference to require the values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    132. 132. The Query Execution• Query definition doesnt execute the query• Instead, defines the query that will run when its time to retrieve the data• To execute, need to run code that forces query reference to require the values  In this course, For Each loop generally forces Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    133. 133. Returning Multiple Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    134. 134. Returning Multiple Values• Want to return multiple values? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    135. 135. Returning Multiple Values• Want to return multiple values?• In general, two options: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    136. 136. Returning Multiple Values• Want to return multiple values?• In general, two options:  Create class that exposes properties Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    137. 137. Returning Multiple Values• Want to return multiple values?• In general, two options:  Create class that exposes properties o Specify new instance of class in Select Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    138. 138. Returning Multiple Values• Want to return multiple values?• In general, two options:  Create class that exposes properties o Specify new instance of class in Select  Specify values in Select clause Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    139. 139. Returning Multiple Values• Want to return multiple values?• In general, two options:  Create class that exposes properties o Specify new instance of class in Select  Specify values in Select clause o Compiler creates a new anonymous type containing just the properties you specify Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    140. 140. Creating a Class for Return Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    141. 141. Creating a Class for Return Values• See MyFileInfo class and MultipleReturnValues1 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    142. 142. Using an Anonymous Type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    143. 143. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    144. 144. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    145. 145. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query  Why create a class simply to return values? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    146. 146. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query  Why create a class simply to return values?• Anonymous types generally simpler Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    147. 147. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query  Why create a class simply to return values?• Anonymous types generally simpler• Compiler creates the type, based on values specified in query Select clause Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    148. 148. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query  Why create a class simply to return values?• Anonymous types generally simpler• Compiler creates the type, based on values specified in query Select clause  You dont know the types name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    149. 149. Using an Anonymous Type• In previous example, code created a simple type (MyFileInfo)  Type contained properties returned by query  Why create a class simply to return values?• Anonymous types generally simpler• Compiler creates the type, based on values specified in query Select clause  You dont know the types name  Implicit type definition makes it possible to work with the anonymous type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    150. 150. Deferred Execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    151. 151. Deferred Execution• Defining query doesnt cause query to execute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    152. 152. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    153. 153. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    154. 154. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words:  Creating query doesnt return data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    155. 155. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words:  Creating query doesnt return data  Provides potential for returning data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    156. 156. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words:  Creating query doesnt return data  Provides potential for returning data• Can take advantage of deferred execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    157. 157. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words:  Creating query doesnt return data  Provides potential for returning data• Can take advantage of deferred execution  Break query into small steps without fear of multiple trips to the server for data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    158. 158. Deferred Execution• Defining query doesnt cause query to execute• Must actually force execution by requesting data• In other words:  Creating query doesnt return data  Provides potential for returning data• Can take advantage of deferred execution  Break query into small steps without fear of multiple trips to the server for data  Makes debugging simpler, as well Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    159. 159. Converting Results to Force Execution Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    160. 160. Converting Results to Force Execution• Sometimes, might want to immediately execute query and cache its results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    161. 161. Converting Results to Force Execution• Sometimes, might want to immediately execute query and cache its results• Can use method like ToList or ToArray Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    162. 162. Converting Results to Force Execution• Sometimes, might want to immediately execute query and cache its results• Can use method like ToList or ToArray• Each executes query, and returns results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    163. 163. Agenda Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    164. 164. Agenda• Language Integrated Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    165. 165. Agenda• Language Integrated Query• Structure of a LINQ Query Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    166. 166. Agenda• Language Integrated Query• Structure of a LINQ Query• Some LINQ Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    167. 167. Some LINQ Examples Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    168. 168. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    169. 169. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ• Introduce some of the new language features for LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    170. 170. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ• Introduce some of the new language features for LINQ• Examples of: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    171. 171. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ• Introduce some of the new language features for LINQ• Examples of:  LINQ to Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    172. 172. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ• Introduce some of the new language features for LINQ• Examples of:  LINQ to Objects  LINQ to SQL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    173. 173. Some LINQ Examples• Get a taste of the kinds of things you can do with LINQ• Introduce some of the new language features for LINQ• Examples of:  LINQ to Objects  LINQ to SQL  LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    174. 174. LINQ to Objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    175. 175. LINQ to Objects• Can use any collection that implements IEnumerable (or generic version) as data source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    176. 176. LINQ to Objects• Can use any collection that implements IEnumerable (or generic version) as data source• Note example uses multiple overloaded versions of DisplayResults procedure Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    177. 177. Query Syntax/Extension Methods(C#) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    178. 178. Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like select, where, and orderby into executable code? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    179. 179. Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like select, where, and orderby into executable code?  Keywords need to be converted into methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    180. 180. Query Syntax/Extension Methods(C#)• How does language compiler turn keywords like select, where, and orderby into executable code?  Keywords need to be converted into methods• Each LINQ keyword corresponds to a single method of the System.Linq.Enumerable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    181. 181. Query Syntax/Extension Methods(VB) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    182. 182. Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like Select, Where, and Order By into executable code? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    183. 183. Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like Select, Where, and Order By into executable code?  Keywords need to be converted into methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    184. 184. Query Syntax/Extension Methods(VB)• How does language compiler turn keywords like Select, Where, and Order By into executable code?  Keywords need to be converted into methods• Each LINQ keyword corresponds to a single method of the System.Linq.Enumerable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    185. 185. Continuing the Investigation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    186. 186. Continuing the Investigation• So compiler converts keywords into methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    187. 187. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    188. 188. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    189. 189. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on  Where do those methods come from? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    190. 190. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on  Where do those methods come from?• LINQ requires ability to extend existing interfaces/classes without changing their definitions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    191. 191. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on  Where do those methods come from?• LINQ requires ability to extend existing interfaces/classes without changing their definitions  Available because of new extension methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    192. 192. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on  Where do those methods come from?• LINQ requires ability to extend existing interfaces/classes without changing their definitions  Available because of new extension methods• Extension method exists in one class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    193. 193. Continuing the Investigation• So compiler converts keywords into methods• But IEnumerable is an old interface  It doesnt support Where, Select, and so on  Where do those methods come from?• LINQ requires ability to extend existing interfaces/classes without changing their definitions  Available because of new extension methods• Extension method exists in one class  Allows code to extend a different class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    194. 194. Extension Methods (VB) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    195. 195. Extension Methods (VB)• Add new methods to existing classes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    196. 196. Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    197. 197. Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    198. 198. Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    199. 199. Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending  Exist within a module Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    200. 200. Extension Methods (VB)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending  Exist within a module  Include the <Extension()> attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    201. 201. Extension Methods (C#) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    202. 202. Extension Methods (C#)• Add new methods to existing classes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    203. 203. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    204. 204. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    205. 205. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    206. 206. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending  Exist within a static class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    207. 207. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending  Exist within a static class  Be a static method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    208. 208. Extension Methods (C#)• Add new methods to existing classes• Not just for LINQ, but crucial for LINQ• Extension methods must:  Accept a parameter, the type of which defines the class that you’re extending  Exist within a static class  Be a static method  Include the this keyword in the parameter Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    209. 209. Using LINQ to Group Output Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    210. 210. Using LINQ to Group Output• System.Linq.Enumerable class provides large number of methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    211. 211. Using LINQ to Group Output• System.Linq.Enumerable class provides large number of methods• Look for grouping methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    212. 212. LINQ to SQL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    213. 213. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    214. 214. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    215. 215. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    216. 216. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties• To support LINQ to SQL, must add custom .NET attributes to class that represents the schema Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    217. 217. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties• To support LINQ to SQL, must add custom .NET attributes to class that represents the schema• Map a class to a table Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    218. 218. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties• To support LINQ to SQL, must add custom .NET attributes to class that represents the schema• Map a class to a table  Map properties within the class to columns Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    219. 219. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties• To support LINQ to SQL, must add custom .NET attributes to class that represents the schema• Map a class to a table  Map properties within the class to columns  All by adding attributes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    220. 220. LINQ to SQL• Allows standard LINQ queries to work with data stored in relational databases  Extends ADO.NET  Adds support for mapping tables and rows to classes and properties• To support LINQ to SQL, must add custom .NET attributes to class that represents the schema• Map a class to a table  Map properties within the class to columns  All by adding attributes• Can represent relationships as well Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    221. 221. Linking a Class to SQL Server Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    222. 222. Linking a Class to SQL Server• Retrieve data from Northwind Customers table Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    223. 223. Linking a Class to SQL Server• Retrieve data from Northwind Customers table• Retrieve CustomerID, CompanyName, ContactName, Country, Region Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    224. 224. Linking a Class to SQL Server• Retrieve data from Northwind Customers table• Retrieve CustomerID, CompanyName, ContactName, Country, Region• Indicate primary key, columns, and rename column Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    225. 225. Creating the Class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    226. 226. Creating the Class• Start by creating a class with properties that correspond to columns in the database Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    227. 227. Creating the Class• Start by creating a class with properties that correspond to columns in the database• See Customer1 class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    228. 228. Marking Up the Class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    229. 229. Marking Up the Class• Use attributes from the System.Data.Linq.Mapping namespace Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    230. 230. Marking Up the Class• Use attributes from the System.Data.Linq.Mapping namespace  Table Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    231. 231. Marking Up the Class• Use attributes from the System.Data.Linq.Mapping namespace  Table  Column Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    232. 232. Marking Up the Class• Use attributes from the System.Data.Linq.Mapping namespace  Table  Column  Many others Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    233. 233. Marking Up the Class• Use attributes from the System.Data.Linq.Mapping namespace  Table  Column  Many others• See Customer class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    234. 234. Retrieving a Collection of Customers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    235. 235. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    236. 236. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    237. 237. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data  Need some class that converts requests for data into SQL strings, and executes/virtualizes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    238. 238. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data  Need some class that converts requests for data into SQL strings, and executes/virtualizes• System.Data.Linq.DataContext class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    239. 239. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data  Need some class that converts requests for data into SQL strings, and executes/virtualizes• System.Data.Linq.DataContext class  Includes members that provide access to data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    240. 240. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data  Need some class that converts requests for data into SQL strings, and executes/virtualizes• System.Data.Linq.DataContext class  Includes members that provide access to data  Tracks changes to data for updates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    241. 241. Retrieving a Collection of Customers• Need some mechanism to manage connection between class and data  Cant simply fill some huge data structure with all the data  Need some class that converts requests for data into SQL strings, and executes/virtualizes• System.Data.Linq.DataContext class  Includes members that provide access to data  Tracks changes to data for updates  O/R designer creates classes, and new class that inherits from DataContext Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    242. 242. Determining the Actual SQL String Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    243. 243. Determining the Actual SQL String• Set Log property of DataContext to stream Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    244. 244. Determining the Actual SQL String• Set Log property of DataContext to stream  Sends all information to the output stream Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    245. 245. Determining the Actual SQL String• Set Log property of DataContext to stream  Sends all information to the output stream• To simply see the SQL string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    246. 246. Determining the Actual SQL String• Set Log property of DataContext to stream  Sends all information to the output stream• To simply see the SQL string  Call ToString method of query variable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    247. 247. Working with Anonymous Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    248. 248. Working with Anonymous Types• Anonymous types work well with LINQ to SQL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    249. 249. Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    250. 250. Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns  Or perform a calculation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    251. 251. Working with Anonymous Types• Anonymous types work well with LINQ to SQL• Often need to retrieve just a subset of columns  Or perform a calculation• See DemoLinqToSqlWithAnonymousTypes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    252. 252. LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    253. 253. LINQ to XML• Need to retrieve, create, query XML? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    254. 254. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    255. 255. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    256. 256. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    257. 257. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath• What if you could accomplish these using a standard syntax? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    258. 258. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath• What if you could accomplish these using a standard syntax?• That is, what about LINQ? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    259. 259. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath• What if you could accomplish these using a standard syntax?• That is, what about LINQ?• LINQ to XML makes it possible Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    260. 260. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath• What if you could accomplish these using a standard syntax?• That is, what about LINQ?• LINQ to XML makes it possible• Examples create XML content Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    261. 261. LINQ to XML• Need to retrieve, create, query XML?• .NET Framework provides rich support  Steps can be complex  Can require XSLT and XPath• What if you could accomplish these using a standard syntax?• That is, what about LINQ?• LINQ to XML makes it possible• Examples create XML content  Examine Course class, and CreateCourseList Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    262. 262. Life without LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    263. 263. Life without LINQ to XML• Without LINQ to XML, creating XML content required multiple steps Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    264. 264. Life without LINQ to XML• Without LINQ to XML, creating XML content required multiple steps  XmlDocument creates new elements Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    265. 265. Life without LINQ to XML• Without LINQ to XML, creating XML content required multiple steps  XmlDocument creates new elements  Set properties Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    266. 266. Life without LINQ to XML• Without LINQ to XML, creating XML content required multiple steps  XmlDocument creates new elements  Set properties  Append as child of new parent Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    267. 267. Life without LINQ to XML• Without LINQ to XML, creating XML content required multiple steps  XmlDocument creates new elements  Set properties  Append as child of new parent• See DemoNoLinqToXml Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    268. 268. Using System.Xml.Linq Classes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    269. 269. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    270. 270. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    271. 271. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment  All inherit from XObject Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    272. 272. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment  All inherit from XObject• Each provides overloaded constructors Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    273. 273. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment  All inherit from XObject• Each provides overloaded constructors  You pass as much information as necessary to generate the XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    274. 274. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment  All inherit from XObject• Each provides overloaded constructors  You pass as much information as necessary to generate the XML  More readable than XmlDocument code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    275. 275. Using System.Xml.Linq Classes• System.Xml.Linq namespace adds classes  XElement, XAttribute, XComment  All inherit from XObject• Each provides overloaded constructors  You pass as much information as necessary to generate the XML  More readable than XmlDocument code• Examine CreateXmlContent Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    276. 276. Creating Data: From and Select Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    277. 277. Creating Data: From and Select• From clause sets up range variable iterating over data source Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    278. 278. Creating Data: From and Select• From clause sets up range variable iterating over data source• Select clause specifies "shape" of resulting data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    279. 279. Creating Data: From and Select• From clause sets up range variable iterating over data source• Select clause specifies "shape" of resulting data• Take advantage of these facts to use LINQ to generate XML content Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    280. 280. Creating Data: From and Select• From clause sets up range variable iterating over data source• Select clause specifies "shape" of resulting data• Take advantage of these facts to use LINQ to generate XML content• Examine DemoLinqToXml Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    281. 281. Visual Basic Only (VB) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    282. 282. Visual Basic Only (VB)• Only Visual Basic adds new features that make it far easier to work with LINQ to XML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    283. 283. Visual Basic Only (VB)• Only Visual Basic adds new features that make it far easier to work with LINQ to XML  XML literals Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    284. 284. Visual Basic Only (VB)• Only Visual Basic adds new features that make it far easier to work with LINQ to XML  XML literals  XML replacement tokens Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    285. 285. Visual Basic Only (VB)• Only Visual Basic adds new features that make it far easier to work with LINQ to XML  XML literals  XML replacement tokens• See CreateXmlContentVBOnly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    286. 286. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
    287. 287. Learn More!• This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

    ×