With NHibernate, you design your code independent of the database layout. You don't have to (and don't should to) create classes that are exactly the same as your database tables and columns.
Example:
public class User
{
public IList<Address> Addresses { get; private set; }
public int Id { get; set; }
}
The mapping depends on what the relationship between address and user is:
- Can a user have multiple addresses?
- Can multiple users have the same address?
- What do you want to inner join on what? (I would expect a many to many
relationship here with an outer join)
In a scenario when a user has multiple addresses and those addresses can be used by different users, you can use many to many mapping to map the address.
The mapping also depends on how you want to create your user and address classes.
- Is it logical to have a list of addresses in a user?
- Is it logical to have a list of users in an address?
- Can a user have the same address twice?
The idea of NHibernate is: write code the way you like it, and add mapping to a database to it later.