SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 62 | Next

Scott Klein

"Professional LINQ"

Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim context As DataContext = New DataContext("Initial
Catalog=AdventureWorks;Integrated Security=sspi")
Dim contact As Table(Of Contact) = context.GetTable(Of Contact)()
Dim query = From c In contact Select c.FirstName, c.LastName, Email =
c.EmailAddress
For Each item In query
ListBox1.Items.Add(item.FirstName & " " & item.LastName & " " & item.Email)
Next item
End Sub
25
Part I: Introduction to Project LINQ
You need to pay close attention to object initializers of named and anonymous types. Their declarations
look nearly the same, but they are indeed different and they have different effects. For example, the
following illustrates how to initialize a named instance:
Dim cont = new Contact with {.FirstName = "Scott"}
However, the initializer for an anonymous type cannot include a class name because it has no usable
name, as illustrated here:
Dim cont = New With {.FirstName = "Scott"}
These two declarations do not produce the same result. The first example has a Contact class that
contains a FirstName property that must already exist, and the declaration takes the step of creating
an instance of the Contact class.


Pages:
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6