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 142 | Next

Scott Klein

"Professional LINQ"

FirstName).ToList();
76
Chapter 4: LINQ Standard Query Operators
foreach (string item in query)
listBox1.Items.Add(item);
ToLookup
The ToLookup operator puts the returned elements into a Lookup(Of Tkey, TElement), based on a speci-
fied key. A Lookup is a collection of keys, each of which is mapped to one or more values; you can think
of it as a one-to-many dictionary.
The following example uses the ToLookup operator to create and populate a Lookup(Of TKey,
TElement)and then iterate through that Lookup to populate a list box.
DataContext context = new DataContext("Initial Catalog =
AdventureWorks;Integrated Security=sspi");
Table contact = context.GetTable();
Lookup lkp = contact.ToLookup(con => con.FirstName,
con => con.MiddleName + " " + con.LastName);
foreach (IGrouping lkpgrp in lkp)
{
listBox1.Items.Add(lkpgrp.Key);
foreach (string item in lkpgrp)
listBox1.Items.Add(" " + item);
}
In this example, a Lookup is created, and contacts??™ first, middle, and last names are used to populate the
Lookup, using the contact??™s last name as a key.


Pages:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6