Pro Entity Framework 4.0 - Apress_3

đến nay trong chương này, bạn đã làm việc với các thực thể duy nhất mà không cần đối phó với bất kỳ của các hiệp hội hoặc các mối quan hệ của họ. Trong ví dụ trước, bạn đã cập nhật hoặc chèn vào các bảng hoạt động trong một vai trò cha mẹ, chẳng hạn như ProductModel và người. | 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

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
2    394    1    29-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.