views:

267

answers:

1

Hi, I have a Customer table and an AddressTable. My table looks like this :

Table Customer
{
ID,
Name
}

Table Address
{
ID,
CustomerID,
AddressType,
Address
}

(AddressType is 1 for HomeAddress and 2 for WorkAddress)

In my Customer class I have 2 properties for Address type

class Customer
{
 Address HomeAdress;
 Address WorkAddress;
}

How can I map these two properties by using FluentNHibernate ?

Thanks.

+1  A: 

You map the two addresses as components of Customer. This link explains component mapping and uses an address class as an example.

Edited to add: I'm completely missed that Address was a separate table so my first response is wrong. Hopefully this is more helpful: You have a one-to-many relationship between Customer and Address. One way to map this is to map a private collection of Addresses on Customer, then expose properties for HomeAddress and WorkAddress.

Jamie Ide
Thanks but Customer and Address are different tables. I cant map them as components. Can I ?
SerhaD
No, you can't, my first answer is wrong. I've updated it with a better answer.
Jamie Ide