Đang chuẩn bị liên kết để tải về tài liệu:
CHAPTER 5 ■ WORKING WITH ENTITIES In this example, you use the CreateProductModel method to

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

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. | 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 context.ProductModels.Where pm pm.ProductModelID 129 .First var prod new Product prod.Name Inverted Kayaba prod.ProductNumber IKAYA-R209 prod.MakeFlag true prod.FinishedGoodsFlag true prod.Color Red prod.SafetyStockLevel 250 prod.ReorderPoint 250 prod.StandardCost 2500 prod.ListPrice 3900 prod.Size 40M prod.SizeUnitMeasureCode CM prod.WeightUnitMeasureCode LB prod.Weight decimal 45.2 prod.DaysToManufacture 5 prod.ProductLine S prod.Class M prod.Style M prod.ProductSubcategoryID 1 prod.SellStartDate DateTime.Now prod.ModifiedDate DateTime.Now prod.rowguid Guid.NewGuid prod.ProductModel prodMod context.SaveChanges label1.Text Save Successful catch Exception ex MessageBox.Show ex.InnerException.Message 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

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.