After reading the help file and looking at sample diagrams, I still do not understand the Associations Editor dialog box. Could someone explain how I need to fill out the Association Dialogs? I will (hopefully) come to understand the dialog box through the solution to what I am trying to do.
I am trying to create a diagram (model first) to be used with NHibernate. With the class and property names changed to protect the innocent, it has a "Humans" class of which an instance represents a person such as "Bob." I have another class "Hobbies" of which each instance represents a Hobby such as "Crafting Piñatas" or "Making Mouse Traps." I have a class "HobbyType" that represents types of hobbies such as "Crafts" or "Outdoor Adventures."
The Humans class has a property named "HisHobbies" which I want to hold a set of instances of Hobbies (in relational-speak, presumably a set of Hobbies.HobbiesIDs). The Hobbies table has a property named "HobType" which should be a reference to a single instance of HobbyType.
How do I fill out the Association Dialogs to do this?
Thanks,
Greg
How to fill out Associations Dialog Box?
Please create three classes on your diagram:
- Humans with properties: HumanId (primary key), Name
- Hobbies with properties: HobbyId (primary key), Name
- HobbyTypes with properties: HobbyTypeId (primary key), Name
Add associations in the following way:
1) right click on the Hobbies class > Add > Association and set
End 1 -
Class: Hobbies
Multiplicity: 1 (One)
Generate related property (selected)
Primary key of Hobbies (selected)
End 2 -
Class: Humans
Multiplicity: *(Many)
Generate related property (selected)
Collection type: Set
and press OK.
2) right click on the HobbyTypes class > Add > Association and set
End 1 -
Class: HobbyTypes
Multiplicity: 1 (One)
Generate related property (selected)
Primary key of HobbyTypes (selected)
End 2 -
Class: Hobbies
Multiplicity: *(Many)
Generate related property (selected)
Collection type: Set
and press OK.
Then right click on the diagram surface > Generate Database Script From Model, navigate through the wizard steps and make sure that the correct script for the database is generated.
- Humans with properties: HumanId (primary key), Name
- Hobbies with properties: HobbyId (primary key), Name
- HobbyTypes with properties: HobbyTypeId (primary key), Name
Add associations in the following way:
1) right click on the Hobbies class > Add > Association and set
End 1 -
Class: Hobbies
Multiplicity: 1 (One)
Generate related property (selected)
Primary key of Hobbies (selected)
End 2 -
Class: Humans
Multiplicity: *(Many)
Generate related property (selected)
Collection type: Set
and press OK.
2) right click on the HobbyTypes class > Add > Association and set
End 1 -
Class: HobbyTypes
Multiplicity: 1 (One)
Generate related property (selected)
Primary key of HobbyTypes (selected)
End 2 -
Class: Hobbies
Multiplicity: *(Many)
Generate related property (selected)
Collection type: Set
and press OK.
Then right click on the diagram surface > Generate Database Script From Model, navigate through the wizard steps and make sure that the correct script for the database is generated.