tailieunhanh - [FSC]Apress Pro Entity Framework 4.0_5

In this example, you use the CreateProductModel method to create a new ProductModel object. This method lets you specify the property values in the method overload. Then, as in the previous example, you add that object to the ProductModel using the AddToProductModel method. | CHAPTER 5 WORKING WITH ENTITIES In this example you use the CreateProductModel method to create a new ProductModel object. This method lets you specify the property values in the method overload. Then as in the previous example you add that object to the ProductModel using the AddToProductModel method. Relational Inserts So far in this chapter you ve worked with single entities without dealing with any of their associations or relationships. In the previous examples you ve updated or inserted into tables that act in a parent role such as ProductModel and Person. But in reality developers work with relational data and that means working with child entities. Product suppliers may add product models on occasion but they add related products much more often. The EF needs to be able to insert related child data easily. Fortunately it does this quite well. Let s illustrate this functionality with an example. For this example add another button to your form and add the following code to the button s Click event try using var context new AdventureWorks2008Entities . var prodMod pm 129 .First var prod new Product Inverted Kayaba IKAYA-R209 true true Red 250 250 2500 3900 40M CM LB decimal 5 S M M 1 prodMod Save Successful catch Exception ex 89 CHAPTER 5 WORKING WITH ENTITIES In this example a new Product is created in memory and then attached to the related ProductModel that was queried and returned from the data store. After it s attached

TỪ KHÓA LIÊN QUAN