slide1
Download
Skip this Video
Download Presentation
This is without some of the graphics and sound

Loading in 2 Seconds...

play fullscreen
1 / 84

This is without some of the graphics and sound - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

This is without some of the graphics and sound. WELCOME! Finding the Missing LINQ: the new query language in VB 2008. Thursday, March 12 th 10:45-11:45, Veranda E Diane Zak. LINQ. L anguage IN tegrated Q uery. Sounds impressive!. WHAT?. Why?. Software Elements. Code. Data.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'This is without some of the graphics and sound' - chana


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
welcome finding the missing linq the new query language in vb 2008

WELCOME!Finding the Missing LINQ:the new query language in VB 2008

Thursday, March 12th

10:45-11:45, Veranda E

Diane Zak

slide3
LINQ

Language INtegrated Query

software elements
Software Elements

Code

Data

Visual Basic

C#

C++

Java

text file

array

structure

class

database

slide6
“It was like you had to order your dinner in one language and drinks in another.”

Jason McConnell

VS Product Manager

I’ll have the tuna salad and a vaso de té.

slide8
Why should I learn LINQ?

Access data from any data source

Arrays

Structures

Classes

Databases

XML, Collections, Objects, Lists, Dictionaries

why should i learn linq
Why should I learn LINQ?

Imperative language

Declarative language

You state the problem and the language decides how to solve it

  • Assumes YOU know how to solve the problem
slide11
OK, I’m convinced!

Let’s get started…

my goal
My goal?

Help YOU learn and teach LINQ

when can i start teaching linq
When can I start teachiNG LINQ?

Arrays

Structures

Classes

Databases

basic syntax
Basic Syntax

results= From elementInsource

[Wherecondition]

[Order By element]

Selectelement

results from element in source where condition order by element select element
results= From elementInsource [Wherecondition] [Order By element]Selectelement

Dim filter =From month InstrMonths _

Order By month Select month

Dim strMonths() As String = {“January”, “February”, … “December”}

Be sure Option Infer is On

displaying the contents of the collection
Displaying the contents of the collection

For Each x In filter

lstMonths.Items.Add(x)

Next x

results from element in source where condition order by element select element19
results= From elementInsource [Wherecondition] [Order By element]Selectelement

Dim filter = From month In strMonths _

Order By month

Dim strMonths() As String = {“January”, “February”, … “December”}

Select month

Descending

results from element in source where condition order by element select element21
results= From elementInsource [Wherecondition] [Order By element]Selectelement

Dim filter = From month In strMonths _

Select month

Dim strMonths() As String = {“January”, “February”, … “December”}

Where month = “June”

results from element in source where condition order by element select element22
results= From elementInsource [Wherecondition] [Order By element]Selectelement

Dim filter = From month In strMonths _

Select month

Dim strMonths() As String = {“January”, “February”, … “December”}

Where month.Substring(0, 1) = “J”

Where month Like “J*”

Where month.StartsWith(“J*”)

results from element in source where condition order by element select element23
results= From elementInsource [Wherecondition] [Order By element]Selectelement

Dim filter = From month In strMonths _

_

Select month

Dim strMonths() As String = {“January”, “February”, … “December”}

Where month.Length > 7 Order By month

slide25
Structure monthInfo

Public strName As String

Public intDays As Integer

End Structure

Dim months(11) As monthInfo

months(0).strName = “January”

months(0).intDays = 31

months(11).strName = “December”

months(11).intDays = 31

sort the month names in ascending order and then display them
Sort the month names in ascending order, and then display them

Dim filter = From month In months _

Order By month.strName _

Select month.strName

For Each x In filter

lstMonths.Items.Add(x)

Next x

sort the month names in ascending order and then display the names and days
Sort the month names in ascending order, and then display the names and days

Dim filter = From month In months Order By month.strName _

Select month

Select month.strName,month.intDays

For Each x In filter

lstMonths.Items.Add(x.strName.PadRight(15) & x.intDays)

Next x

sort the months in descending order by days and then in ascending order by name
Sort the months in descending order by days, and then in ascending order by name

Dim filter = From month In months _

Order By month.intDays Descending, month.strName

select the names of the months having 30 days
Select the names of the months having 30 days

Dim filter = From month In months _

Where month.intDays = 30 Select month.strName

select the names of the months having 30 days and more than 5 characters
Select the names of the months having 30 days and more than 5 characters

Dim filter = From month in months _

Where month.intDays = 30 _

AndAlso month.strName.Length > 5 _

Select month.strName

intermission
Intermission

Candy! Candy!

slide35
Properties of the MovieInfo class:

Quote (String)

Title (String)

Character (String)

Actor (String)

Filename (String)

Year (Integer)

Private movies(10) As MovieInfo

what is the title of the movie that contains the selected quote
What is the title of the movie that contains the selected quote?

Dim filter = From m In movies _

Where m.Quote = lstQuotes.SelectedItem _

Select m.Title

which character said the selected quote
Which character said the selected quote?

Dim filter = From m In movies _

Where m.Quote = lstQuotes.SelectedItem _

Select

m.Character

the selected quote is associated with which actor and movie
The selected quote is associated with which actor and movie?

Dim filter = From m In movies _

Where m.Quote = lstQuotes.SelectedItem _

Select

m.Title, m.Actor

how can you play the selected quote
How can you play the selected quote?

Dim filter = From m In movies _

Where m.Quote = lstQuotes.SelectedItem _

Select m.Filename

For Each x In filter

Next x

My.Computer.Audio.Play(x)

which movies were made after 1996
Which movies were made after 1996?

Dim filter = From m In movies _

Where m.Year > 1996 Select m.Title

Distinct

A

B

intermission45
Intermission

Irish mints!

slide47
Linq Aggregation operators

Luck of the Irish

Average

Count

Max

Min

Sum

slide48
Luck of the Irish

Basic syntax

Average

Count

Max

Min

Sum

Dimvariable[AsdataType]= Aggregate elementInsource

[Wherecondition]

SelectelementIntoaggregationOperator

slide49
Dimvariable[AsdataType]= Aggregate elementInsource

[Wherecondition]

SelectelementIntoaggregationOperator

Dim intClovers() As Integer= {0, 0, 1, 2, 5, 6, 8, 4, 3, 2, 1, 0}

Dim intSum As Integer = Aggregate clover In intClovers _

Select clover Into Sum()

slide50
Dimvariable[AsdataType]= Aggregate elementInsource

[Wherecondition]

SelectelementIntoaggregationOperator

Dim intClovers() As Integer= {0, 0, 1, 2, 5, 6, 8, 4, 3, 2, 1, 0}

Dim dblAvg As Double = Aggregate clover In intClovers _

Select clover Into Average()

slide51
Dimvariable[AsdataType]= Aggregate elementInsource

[Wherecondition]

SelectelementIntoaggregationOperator

Dim intClovers() As Integer= {0, 0, 1, 2, 5, 6, 8, 4, 3, 2, 1, 0}

Dim intCount As Integer = Aggregate clover In intClovers _

Where clover = 0 _

Select clover Into Count()

slide52
Luck of the Irish

Structure popInfo

Public intGroup As Integer

Public intMales As Integer

Public intFemales As Integer

End Structure

Dim pop2006(4) As popInfo

slide53
How many males in the population?

Dim intTotalMales As Integer = _

Aggregate m In pop2006 _

Select m.intMales Into Sum()

slide54
What is the total population?

Dim intTotal As Integer = _

Aggregate m In pop2006 _

Select m.intMales + m.intFemales _

Into Sum()

slide55
How many groups of females contain over 450,000 people?

Dim intCount As Integer = _

Aggregate c In pop2006 _

Where c.intFemales > 450000 _

Select c.intFemales Into Count()

slide56
Which group has the most males?

Dim intMostMales As Integer = _

Aggregate m In pop2006 _

Select m.intMales Into Max()

Dim strMostMales =

From pop In pop2006 _

Where pop.intMales = intMostMales _

Select pop.strGroup

slide57
What is the percentage of females?

Dim intTotalFem As Integer = Aggregate f In pop2006 _

Select f.intFemales Into Sum()

Dim intTotal As Integer = Aggregate t In pop2006 _

Select t.intFemales + t.intMales Into Sum()

Dim dblAvg As Double = intTotalFem / intTotal

intermission58
Intermission

the king of rock and roll!

slide60
Elvis Database

Movies table

ID Auto

Title Text

Released Date

Studio Text

Sample record:

15

Viva Las Vegas

5/6/1964

MGM

slide61
You are looking

a bit frazzled!

slide62
How many movies did Elvis make?

Dim intCount As Integer = _

Aggregate m In ElvisDataSet.Movies _

Select m Into Count()

slide63
How many of his movies were released in 1965?

Dim intCount As Integer = _

Aggregate m In ElvisDataSet.Movies _

Where m.Released.ToShortDateString.EndsWith("1965") _

Select m Into Count()

slide64
Which movie was produced by Allied Artists?

Dim filter = From m In ElvisDataSet.Movies _

Where m.Studio = “Allied Artists” _

Select m.Title

slide65
How many of his movies were produced by MGM?

Dim intCount As Integer = _

Aggregate m In ElvisDataSet.Movies _

Where m.Studio = “MGM”

Select m Into Count()

slide66
When was Love Me Tender released?

Dim filter = From m In ElvisDataSet.Movies _

Where m.Title = “Love Me Tender” _

Select m.Released

slide67
What studio produced Clambake?

Dim filter = From m In ElvisDataSet.Movies _

Where m.Title = “Clambake” _

Select m.Studio

slide68
What movie was released on 11/10/1957?

Dim filter = From m In ElvisDataSet.Movies _

Where m.Released = #11/10/1957# _

Select m.Title

slide69
What was his last movie?

Dim dtmLast As Date = _

Aggregate m In ElvisDataSet.Movies _

Select m.Released Into Max()

Dim filter = From m In ElvisDataSt.Movies _

Where m.Released = dtmLast Select m.Title

slide70
How many of his movies have one-word titles?

Dim intCount As Integer = _

Aggregate m In ElvisDataSet.Movies _

Where Not m.Title.Contains(“ ”) _

Select m.Title Into Count()

it s time for
It’s Time for

Elvis bingo

slide82
I hope you enjoyed this presentation on LINQ.

Thank you

for being such a great audience!

Diane Zak

slide83
Dim intSales() As Integer = {100, 200, 300}

Dim dblRate() As Double = {0.05, 0.1, 0.4}

Dim filter = From sales In intSales _

From rate In dblRate _

Let commission = sales * rate _

Select sales, rate, commission

slide84
Dim strData() As String = _

{"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}

Dim filter = From x In strData _

Group x By FirstLetter = x.Substring(0, 1) _

Into Group Order By FirstLetter Select FirstLetter, words = Group

For Each letterGroup In filter

lblInfo.Text = lblInfo.Text & letterGroup.FirstLetter & ControlChars.NewLine

For Each w In letterGroup.words

lblInfo.Text = lblInfo.Text & " " & w & ControlChars.NewLine

Next w

Next letterGroup

ad