Name the combo box salesPerson and
name the grid grdOrderDetail. Next, double-click on the form itself to view the code behind. Add the
following two statements to the top of the form:
using System.Data.Objects;
using AdventureWorksModel;
337
Appendix B: LINQ to Entities: The ADO.NET Entity Framework
Add the following line of code to the top of the partial class for the form:
private AdventureWorksEntities productSalesContext;
Add the following code to the Load event of the form:
productSalesContext = new AdventureWorksEntities();
grdProducts.Columns.Add("OrderID", "Order");
grdProducts.Columns.Add("OrderQty", "Quantity");
grdProducts.Columns.Add("ProductID", "Product");
grdProducts.Columns.Add("UnitPrice", "Price");
grdProducts.Columns.Add("LineTotal", "Total");
ObjectQuery
salesPerson = productSalesContext.Contact.Where("it
.MiddleName IS NOT NULL").OrderBy("it.LastName");
this.cbosalesPerson.DataSource = salesPerson.Include
("SalesOrderHeader.SalesOrderDetail");
this.cbosalesPerson.DisplayMember = "LastName";
Finally, add the following code to the SelectedIndexChanged event of the combo:
grdProducts.
Pages:
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523