Mapping an Entity to Several Tables

This topic deals with the join tables functionality available in Entity Developer for NHibernate, that allows mapping properties of one class to several tables, when there's a 1-to-1 relationship between the tables.

 

ExpandedToggleIcon        Joining Tables in Entity Developer

For the purposes of the example below, we create a database containing the Orders and OrderDetails tables linked through a one-to-one association:

Images_JT_Diagram

We perform the following sequence of operations:

create an NHibernate model;
add the Orders and OrderDetails tables to the model (prior to performing this step, make sure that the Detect Table Per Type Inheritances check box in the Model Settings dialog box is deselected).

Before joining the table properties into one class, the model looks as follows:

Images_JT_Diagram2

We select the Product, Price and Quantity properties of the OrderDetail entity and drag them into the Order entity. Then we select the Order entity and in the Properties window, locate and click the Join Tables row, and then click the displayed three-dotted button.

The Join Tables Editor dialog box is displayed. Click the Add button to add the Join Table.

Images_JoinTablesEditor

Note, that the Schema property value is set to 'dbo' and the Table property value is changed from the default value to 'OrderDetails'. Besides, under Column in the Key Columns area, we set the primary key name of the OrderDetails table (OrderID).

To complete the procedure of properties mapping, we select the Product, Price and Quantity properties of the Order entity and in the Join Table combo-box of the Properties window, we select the dbo.OrderDetails value. After this we delete the OrderDetail entity from the model.

As a result we have the model with a single Order class and for a part of its properties the Join Table values are defined:

Images_JoinTableProperties

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.