Contact.Wherei
("it.MiddleName IS NOT NULL").OrderBy("it.LastName");
this.cbosalesPerson.DataSource = salesPerson.Include
("SalesOrderHeader.SalesOrderDetail");
Figure B-9
The first line creates an instance of ObjectContext based on the defined entity. The second line initializes
a new instance of the ObjectContext class. The third line uses the defined and mapped entities to return
all contacts that have a middle name. The fourth line sets the data source of the combo box.
How about the IndexChanged event on the combo? The first line of the following code gets the selected
contact from the combo. Because the ADO.NET Entity Framework handles the relationships, the rest of
the code gets the sales order detail for the selected contact, and then populates the grid.
Contact person = (Contact)cbosalesPerson.SelectedItem;
foreach (SalesOrderHeader soh in person.SalesOrderHeader)
{
object[] row = new object[4];
row[0] = soh.SalesOrderDetail.OrderQty;
row[1] = soh.SalesOrderDetail.ProductID;
row[2] = soh.SalesOrderDetail.UnitPrice;
row[3] = soh.
Pages:
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525