Đang chuẩn bị liên kết để tải về tài liệu:
Introducing dot NET 4 0 with Visual Studio_3

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

Cấu trúc lại mô tả và chiều dài thành một loại phức tạp 4. 5. VS sẽ tạo ra một tài sản mới được gọi là ComplexProperty đổi tên tài sản đến chi tiết. Nếu bạn mở Program.cs bây giờ bạn sẽ có thể truy cập vào các đặc tính này bằng cách sử dụng mã tương tự như sau | CHAPTER 8 ENTITY FRAMEWORK Patient.Demographic.FirstName Patient.Demographic.Age Patient.Demographic.LastName Patient.Clinical.BloodType Patient.Financial.InsurerName Previously if you wanted to accomplish this it was necessary to manually edit the CSDL but as of EF4 you can accomplish this in the designer. Let s see how to work with this feature with our Film entity. 1. Select the Film entity. 2. Hold down the Ctrl key and select the Description and Length properties Figure 8-11 . 3. Right-click and select the Refactor into New Complex Type option on the context menu. Figure 8-11. Refactoring description and Length into a complex type 4. VS will create a new property called ComplexProperty rename this property to Detail. 5. If you open Program.cs you will now be able to access these properties using code similar to the following Film Film new Film Film.Detail.Description New film Film.Detail.Length 200 192 CHAPTER 8 ENTITY FRAMEWORK TIP To undo this change remove the Film table from the model designer and then add it in again by rightclicking and selecting Update Model from Database. Complex Types from Stored Procedures The function import wizard will now create complex types from stored procedures. For example let s imagine we wanted to add a method to our Film entity to return information about some of the crew which is retrieved using the following stored procedure mocked up for ease of use CREATE PROCEDURE FilmGetCrewInfo @filmID int AS SELECT James Cameron as Director Arnold Schwarzenegger as LeadActor1 Linda Hamilton as LeadActor2 1. Go to the Model Browser window tab next to Solution Explorer . 2. Right-click on the Complex Types folder and add a new complex type called FilmCrew. 3. Right-click on the newly created complex type and add three new string scalar properties called Director LeadActor1 and LeadActor2 Figure 8-12 . Model Browser X 1 Type here to search Id 4 Chapter8Model.edmx s ióV BookModel j Entity Types I I Film I I FilmShowing I I Order I I .