0

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.

  • Looks like address is a value object, not an entity in this case. I would add a homeaddress and a workaddress field to the customers table and map them as components. – Paco Jun 09 '09 at 21:12

1 Answers1

1

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
  • 48,427
  • 16
  • 81
  • 117