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

Scott Klein

"Professional LINQ"

SalesPersonID,
SalesOrderHeader => SalesOrderHeader.SalesPersonID,
(person, salesorder) => new { SalesPerson = person.SalesPersonID,
orders = salesorder.Select(order => order.CustomerID)} );
foreach (var sao in salespeopleandorders)
61
Part I: Introduction to Project LINQ
{
listBox1.Items.Add(sao.SalesPerson);
foreach (int order in sao.orders)
listBox1.Items.Add(" " + order);
}
}
The results of this query list each salespersonid and the associated order customerid. Here??™s a portion
of the output:
279
676
117
442
227
283
2
107
56
310
527
638
157
Grouping Operator
Grouping is the concept of grouping the values or elements of a sequence according to a specified value
(selector). LINQ contains a single grouping operator, GroupBy.
The following example uses the Sales.SalesOrderHeader table in the AdventureWorks database to
group together orders for each sales person using the SalesPersonID as the key value.
DataContext context = new DataContext("Initial
Catalog=AdventureWorks;Integrated Security=sspi");
Table orders = context.


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