1 / 84

This is without some of the graphics and sound

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.

Download Presentation

This is without some of the graphics and sound

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This is without some of the graphics and sound

  2. WELCOME!Finding the Missing LINQ:the new query language in VB 2008 Thursday, March 12th 10:45-11:45, Veranda E Diane Zak

  3. LINQ Language INtegrated Query

  4. Sounds impressive! WHAT? Why?

  5. Software Elements Code Data Visual Basic C# C++ Java text file array structure class database

  6. “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é.

  7. LinQ truly is the missing link LINQ Code Data

  8. Why should I learn LINQ? Access data from any data source Arrays Structures Classes Databases XML, Collections, Objects, Lists, Dictionaries

  9. Why should I learn LINQ?

  10. 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

  11. OK, I’m convinced! Let’s get started…

  12. My goal? Help YOU learn and teach LINQ

  13. When can I start teachiNG LINQ? Arrays Structures Classes Databases

  14. Time for your first handout!

  15. Basic Syntax results= From elementInsource [Wherecondition] [Order By element] Selectelement

  16. Order By Clause

  17. 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

  18. Displaying the contents of the collection For Each x In filter lstMonths.Items.Add(x) Next x

  19. 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

  20. Where Clause filter

  21. 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”

  22. 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*”)

  23. 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

  24. StructureS

  25. 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

  26. 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

  27. 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

  28. 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

  29. Select the names of the months having 30 days Dim filter = From month In months _ Where month.intDays = 30 Select month.strName

  30. 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

  31. Intermission Candy! Candy!

  32. MOVIE time

  33. Movie Answers

  34. Classes

  35. Properties of the MovieInfo class: Quote (String) Title (String) Character (String) Actor (String) Filename (String) Year (Integer) Private movies(10) As MovieInfo

  36. 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

  37. Which character said the selected quote? Dim filter = From m In movies _ Where m.Quote = lstQuotes.SelectedItem _ Select m.Character

  38. 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

  39. 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)

  40. Which movies were made after 1996? Dim filter = From m In movies _ Where m.Year > 1996 Select m.Title Distinct A B

  41. Intermission Irish mints!

  42. Luck of the Irish

  43. Linq Aggregation operators Luck of the Irish Average Count Max Min Sum

  44. Luck of the Irish Basic syntax Average Count Max Min Sum Dimvariable[AsdataType]= Aggregate elementInsource [Wherecondition] SelectelementIntoaggregationOperator

  45. 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()

  46. 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()

More Related