Danh mục

Pro Entity Framework 4.0 - Apress_4

Số trang: 26      Loại file: pdf      Dung lượng: 1.15 MB      Lượt xem: 17      Lượt tải: 0    
10.10.2023

Phí tải xuống: 18,000 VND Tải xuống file đầy đủ (26 trang) 0
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Thông tin trong trang thuộc tính mà không phải là khác nhau từ EF 3.5, nhưng bạn có thể thấy một số tài sản đặt tên khác biệt cũng như một số bổ sung. Bây giờ bạn có End1 và End2 sự khác biệt, và bạn vẫn có Multiplicity và vai trò cho mỗi đầu. EF 4.0 trên trang này là tài sản onDelete cho mỗi đầu, xác định hành động sẽ được thực hiện khi một thực thể này quy định sẽ bị xóa.
Nội dung trích xuất từ tài liệu:
Pro Entity Framework 4.0 - Apress_4 CHAPTER 7 ■ RELATIONSHIPS AND ASSOCIATIONSFigure 7-6. Entities defined in EF 4.0 Many of the changes that Microsoft made were to the EDM. You can see in Figure 7-7 that theproperties page for the association has been modified. The information in the properties page isn’t thatdifferent from EF 3.5, but you can see some property naming differences as well as a few additions. Younow have End1 and End2 differentiation, and you still have the Multiplicity and Role for each end. Newto EF 4.0 on this page is the OnDelete property for each end, which specifies the action to be taken whenan entity on this specified end is deleted. Your options for the OnDelete property are None and Cascade.Figure 7-7. EF 4.0 association properties 115CHAPTER 7 ■ RELATIONSHIPS AND ASSOCIAATIONS Microsoft also added a couple of new visual items to the UI to help define and manage relationships between entities. These items and features are discussed in the following sections. Defining Referential Constraints Back in the EDM Designer, double-click the association between the two entities. In EF 4.0, a new Referential Constraint dialog opens, showing the foreign key properties for the relationship (see Figure 7-8). Figure 7-8. Referential Contstraint Dialog The Referential Constraint dialog allows you to define the foreign key (FK) constraint between the source entity and the target entity. How do you know which is the target and which is the source? If it isn’t obvious, click Cancel in the Referential Constraint dialog, and hold your mouse cursor over the association line between the two entities. As you hover your mouse over the association line, a small pop-up window displays, showing you which entity is the source and which entity is the target. Double-click the association line again to display the Referential Constraint dialog. This dialog contains FK information. The Principle field displays the source entity and is a drop-down listing the entities defined in the relationship. By default, it lists the source entity in the relationship. The Dependent field shows the source entity. This field isn’t editable. The Principle Key and Dependent Property fields show the two fields that are used in the FK relationship. Adding an Association In your EDM Designer, drag a new entity from the toolbox, and drop it onto the designer surface. Next, right-click the new entity, and select Add ➤ Association from the context menu. Doing so displays the Add Association dialog box, shown in Figure 7-9. This dialog isn’t new to the EF, but Microsoft did make some changes to it, the biggest being the “Add foreign key properties to the entityname Entity” check box.116 CHAPTER 7 ■ RELATIONSHIPS AND ASSOCIATIONSFigure 7-9. Add Association in EF 4.0 When you create an association, this check box lets you specify this association as a FK association.Can you specify a typical (non-FK) association? Absolutely: uncheck the “Add foreign key properties tothe entityname Entity” check box. What does this do? I know I’ve been saying this for a few pages now,but bear with me—I’ll explain shortly. Also new in the Add Association dialog are the Navigation Property check boxes.Looking at XML DifferencesBefore I get into the “I’ll get to that shortly” topics, I want to cover the XML differences between EF 3.5and 4.0. Close the EDM Designer, right-click the EDM, and select Open With from the context menu. Inthe Open With dialog, select XML Editor, and click OK. Let’s first look at the conceptual schema definition language (CSDL) XML for your EF 3.5 project.The XML fragment for the independent association looks like this: The mapping for the association tells the EF how to negotiate the relationship. In EF 3.5 MSL, thatmapping looks as follows: 117CHAPTER 7 ■ RELATIONSHIPS AND ASSOCIAATIONS Now, let’s look at the EF 4.0 XML. The CSDL XML has two sections. The top of the CSDL contains the AssociationSet element: At the end of the CSDL is the following XML fragment, which contains the Referenti ...

Tài liệu được xem nhiều: