NET Entity Framework
foreach (SalesOrderHeader order in query.First().SalesOrderHeader)
{
listbox1.Items.Add(String.Format("Order Date: {0}", order.PurchaseOrderNumber));
listbox1.Items.Add(String.Format("Total: {0}",order.TotalDue.ToString()));
foreach (SalesOrderDetail item in order.SalesOrderDetail)
{
listBox1.Items.Add(String.Format("Product: {0} "
+ "Quantity: {1}", item.Name.ToString(),
item.OrderQty.ToString()));
}
}
Querying the entity data model is quite easy and efficient.
Working with Objects
Let??™s take a look at working with objects that represent entity types defined by an entity data model.
The following example illustrates how to use the entity data model to update and insert data:
string ln = "Kleinerman";
productSalesContext = new AdventureWorksEntities();
Contact con = productSalesContext.Contact.Where("it.LastName = @lastname",
new ObjectParameter("lastname", ln)).First();
con.EmailAddress = "";
con.EmailPromotion = 1;
Contact newcon = new Contact();
newcon.EmailAddress = "asdf";
newcon.EmailPromotion = 1;
newcon.
Pages:
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528