LINQ Demo Script
LINQ Demo Script
Version: 1.1
2007-08-06
Key Messages:
1. LINQ integrates the worlds of Data and Objects.
2. LINQ provides powerful natural language query syntax to access data and objects, with independence of the data source.
3. LINQ focuses on being declarative instead of imperative.
Key Technologies:
The following technologies are utilized within this demo:
Technology / Product
Version
RTM
2. LINQ
3. C# 3.0
4. Visual Basic 9
3. After creating the connection, expand it until all tables are shown.
Opening Statement
Database-centric applications have traditionally two distinct programming languages: one for the database and one for the
application.
In this talk we will introduce LINQ, a component designed to help integrate relational data, XML and other data sources directly
from C# and Visual Basic.
Step-by-step Walkthrough
Estimated time for setting up and configuring the demo: 20 minutes.
Estimated time to complete the demo: 60 minutes.
Script
Screenshot
1
0
12.Type:
foreach(Customer c in LoadCustomers())
{
}
1
1
starts with M.
{
}
1
2
Script
Screenshot
1
3
1
4
1
5
Script
Screenshot
1
6
1
7
1
8
Script
Screenshot
1
9
Script
Screenshot
2
0
LINQ to SQL
Action
Script
Screenshot
2
1
2
2
2
3
2
4
67.Type:
SalesByCategory("Seafood", "");
68.Run the sample (Ctrl+F5)
2
5
LINQ to XML
Action
Script
Console.WriteLine(xml);
Screenshot
71.Type:
2
6
Script
Screenshot
from s in
db.SalesByCategory("Seafood", "")
where s.TotalPurchase < 5000
select new XElement("Sale",
new XAttribute("Name",
s.ProductName),
new XAttribute("Total",
2
7
s.TotalPurchase)));
Console.WriteLine(xml);
2
8
Action
Script
87.Type
84.Open
C:\VS2008TrainingKit\Demos\0
2 LINQ\SuperVB\Module1.vb
85.Go to Project | Set as Startup
project
Console.WriteLine(xml)
Screenshot
2
9
Script
Dim name="Ravioli"
Screenshot
3
0
becomes:
help.
96.Type:
Console.WriteLine(xml2)
Summary
If you just remember 3 things: we merged data with objects, we merged programming languages with data access, and I gave
you a variety of ideas on what you can do with this; we saw the difference on doing things imperatively vs. declaratively; and we
saw that the queries can be made independently from the data source.
3
1
I would add that the queries aren't executed until the time they are accessed, for example in
a foreach statement (deferred execution)
3
2