Apress Introducing dot NET 4 0 with Visual Studio 2010_4
Số trang: 45
Loại file: pdf
Dung lượng: 1.88 MB
Lượt xem: 11
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Trước đây, nếu bạn muốn thực hiện điều này, nó là cần thiết để tự chỉnh sửa các CSDL, nhưng như các EF4 bạn có thể thực hiện điều này trong thiết kế. Chúng ta hãy xem làm thế nào để làm việc với tính năng này với thực thể phim của chúng tôi. 1. 2. 3. Chọn các thực thể phim.
Nội dung trích xuất từ tài liệu:
Apress Introducing dot NET 4 0 with Visual Studio 2010_4 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. Select the Film entity. 1. Hold down the Ctrl key and select the Description and Length properties (Figure 8-11). 2. 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 VS will create a new property called ComplexProperty: rename this property to Detail. 4. If you open Program.cs y ou will now be able to access these properties using code similar to the 5. following: Film Film = new Film(); Film.Detail.Description = New film; Film.Detail.Length = 200;192 CHAPTER 8 ENTITY FRAMEWORK T IP To undo this change, remove the Film t able from the model designer and then add it in again by right-clicking and selecting Update Model from Database.Complex Types from Stored ProceduresThe function import wizard will now create complex types from stored procedures. For example, letsimagine 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 intASSELECTJames Cameron as Director,Arnold Schwarzenegger as LeadActor1,Linda Hamilton as LeadActor2 1. Go to the Model Browser window (tab next to Solution Explorer). Right-click on the Complex Types folder and add a new complex type called FilmCrew. 2. 3. Right-click on the newly created complex type and add three new string scalar properties called Director, LeadActor1, and LeadActor2 (Figure 8-12). Figure 8-12. Creating a new complex type Open Chapter8.Model.edmx and on the designer surface right-click and select the Update Model 4. from Database option. 193 CHAPTER 8 ENTITY FRAMEWORK Under the Stored Procedures node select the FilmGetCrewInfo stored procedure and click Finish. 5. 6. Right-click on the designer surface and select Add Function Import to bring up the screen shown in Figure 8-13. (I also clicked Get Column Information button when completed the other information to populate the stored procedure column information section). Figure 8-13. Add function import screen Enter the function import name GetCrewInfo. 7. Select the stored procedure name FilmGetCrewInfo. 8. Select Complex in the Returns a Collection Of radio button options and then FilmCrew on the 9. dropdown (notice how you have the option to create a complex type from the results of the stored procedure). 10. Click OK. The EF designer will now have added this function to the context where it can be accessed as follows (note you could then move this into your entity using partial classes): var crew = ctx.GetCrewInfo(1); Model Defined Functions Model defined functions allow you to define reusable functions at a model level. To create them at present you must modify the .edmx file directly, although this will probably change in future versions of194 CHAPTER 8 ENTITY FRAMEWORKEF. In our convoluted example we will create a new property for our Film entity that will return the Filmtitle and description separated by a space. Right-click on the Chapter8Model.edmx file and select Open With. 1. 2. Select XML Editor. 3. Find the following section: 4. Add the following inside the previous section: Trim(Film.Title) + + Film.Description Open Program.cs and add the following using directive: 5. using System.Data.Objects.DataClasses; Unfortunate ...
Nội dung trích xuất từ tài liệu:
Apress Introducing dot NET 4 0 with Visual Studio 2010_4 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. Select the Film entity. 1. Hold down the Ctrl key and select the Description and Length properties (Figure 8-11). 2. 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 VS will create a new property called ComplexProperty: rename this property to Detail. 4. If you open Program.cs y ou will now be able to access these properties using code similar to the 5. following: Film Film = new Film(); Film.Detail.Description = New film; Film.Detail.Length = 200;192 CHAPTER 8 ENTITY FRAMEWORK T IP To undo this change, remove the Film t able from the model designer and then add it in again by right-clicking and selecting Update Model from Database.Complex Types from Stored ProceduresThe function import wizard will now create complex types from stored procedures. For example, letsimagine 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 intASSELECTJames Cameron as Director,Arnold Schwarzenegger as LeadActor1,Linda Hamilton as LeadActor2 1. Go to the Model Browser window (tab next to Solution Explorer). Right-click on the Complex Types folder and add a new complex type called FilmCrew. 2. 3. Right-click on the newly created complex type and add three new string scalar properties called Director, LeadActor1, and LeadActor2 (Figure 8-12). Figure 8-12. Creating a new complex type Open Chapter8.Model.edmx and on the designer surface right-click and select the Update Model 4. from Database option. 193 CHAPTER 8 ENTITY FRAMEWORK Under the Stored Procedures node select the FilmGetCrewInfo stored procedure and click Finish. 5. 6. Right-click on the designer surface and select Add Function Import to bring up the screen shown in Figure 8-13. (I also clicked Get Column Information button when completed the other information to populate the stored procedure column information section). Figure 8-13. Add function import screen Enter the function import name GetCrewInfo. 7. Select the stored procedure name FilmGetCrewInfo. 8. Select Complex in the Returns a Collection Of radio button options and then FilmCrew on the 9. dropdown (notice how you have the option to create a complex type from the results of the stored procedure). 10. Click OK. The EF designer will now have added this function to the context where it can be accessed as follows (note you could then move this into your entity using partial classes): var crew = ctx.GetCrewInfo(1); Model Defined Functions Model defined functions allow you to define reusable functions at a model level. To create them at present you must modify the .edmx file directly, although this will probably change in future versions of194 CHAPTER 8 ENTITY FRAMEWORKEF. In our convoluted example we will create a new property for our Film entity that will return the Filmtitle and description separated by a space. Right-click on the Chapter8Model.edmx file and select Open With. 1. 2. Select XML Editor. 3. Find the following section: 4. Add the following inside the previous section: Trim(Film.Title) + + Film.Description Open Program.cs and add the following using directive: 5. using System.Data.Objects.DataClasses; Unfortunate ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính tài liệu công nghệ thông tin lập trình máy tính mẹo máy tính cài đặt máy tínhGợi ý tài liệu liên quan:
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 317 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 305 0 0 -
Thêm chức năng hữu dụng cho menu chuột phải trên Windows
4 trang 289 0 0 -
70 trang 251 1 0
-
Bài giảng Tin học lớp 11 bài 1: Giới thiệu ngôn ngữ lập trình C#
15 trang 238 0 0 -
Tổng hợp lỗi Win 8 và cách sửa
3 trang 233 0 0 -
Sửa lỗi các chức năng quan trọng của Win với ReEnable 2.0 Portable Edition
5 trang 214 0 0 -
Giáo trình Bảo trì hệ thống và cài đặt phần mềm
68 trang 207 0 0 -
Tổng hợp 30 lỗi thương gặp cho những bạn mới sử dụng máy tính
9 trang 204 0 0 -
UltraISO chương trình ghi đĩa, tạo ổ đĩa ảo nhỏ gọn
10 trang 204 0 0