tailieunhanh - Apress introducing ASP.Net 4.0 with visual studio 2010_6

Tham khảo tài liệu 'apress introducing with visual studio 2010_6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 8 ENTITY FRAMEWORK 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 you will now be able to access these properties using code similar to the following Film Film new Film New film 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 s ióV BookModel j Entity Types I I Film I I FilmShowing I I Order I I .

TỪ KHÓA LIÊN QUAN