Schema:
- Users
- ID
- Name
- Password
- Address
- ID
- Street
- UserID
Both tables have an ID field (guid).
Code:
User u = new User();
u.Address.Street = "test";
session.Save(u);
How can I create a mapping file to use the UserID from the address table to point
to the ID from the Users table and reflect my sample code above?
Using many-to-one i sucessfully solve my problem.
but i go search more samples!!
thanks!!
In most of the cases, such kind of mapping should lead to a ‘component’.
In your case, Address could be a component of User.
This means that you’ll have indeed an Adress class, and the User class will have a property of type Adress, but the Address is saved in the Users table in the DB.
If you really want a one-to-one mapping with the DB layout like you want, I suggest you create a one-to-one mapping in the User mapping, and a many-to-one mapping in the Address mapping (with unique set to true). But, I think that this also means that you will be responsible of deleting the old address first if you update the adress of a user …