Rows.Clear();
Contact person = (Contact)cbosalesPerson.SelectedItem;
foreach (SalesOrderHeader soh in person.SalesOrderHeader)
{
object[] row = new object[4];
row[0] = soh.SalesOrderDetail.SalesOrderID;
row[1] = soh.SalesOrderDetail.OrderQty;
row[2] = soh.SalesOrderDetail.ProductID;
row[3] = soh.SalesOrderDetail.UnitPrice;
row[4] = soh.SalesOrderDetail.LineTotal;
grdOrderDetails.Rows.Add(row);
}
Compile the application to make sure everything is OK. Run the application, and when the form loads,
the combo box will be filled with a list of contacts. Selecting a contact will display the order detail for that
contact in the grid, as shown in Figure B-9.
Let??™s take a look on how this works. In the Load method, four columns are defined on the grid, but that
is not the important code. The important code is the following lines:
private AdventureWorksEntities productSalesContext;
productSalesContext = new AdventureWorksEntities();
338
Appendix B: LINQ to Entities: The ADO.NET Entity Framework
ObjectQuery
salesPerson = productSalesContext.
Pages:
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524