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

Scott Klein

"Professional LINQ"

GetTable();
var query = orders.Where(ord => ord.SalesPersonID > 0).GroupBy(order =>
order.SalesPersonID,
order => order.CustomerID);
foreach (var o in query)
{
listBox1.Items.Add(o.Key);
foreach (int cust in o)
listBox1.Items.Add(" " + cust);
}
It can also be written as follows (given the same DataContext and table):
IEnumerable> query = orders.Where(ord =>
ord.SalesPersonID > 0).GroupBy(order => order.SalesPersonID, order =>
order.CustomerID);
62
Chapter 4: LINQ Standard Query Operators
foreach (IGrouping o in query)
{
listBox1.Items.Add(o.Key);
foreach (int cust in o)
listBox1.Items.Add(" " + cust);
}
Here are the results:
268
697
47
471
548
167
...
275
504
618
17
486
269
276
510
511
259
384
650
...
The first example could also be written using a mix of query syntax and method syntax as follows:
var query =
(from o in orders
where o.SalesPersonID > 0
select o).GroupBy(order => order.SalesPersonID,
order => order.CustomerID);
This makes the query somewhat easier to read, even though the example used a mix of the two
syntaxes.


Pages:
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6