views:

19

answers:

1

I have a [ContactNumbers] table as defined below:

ID (PK) | PersonID (FK) | NumberType | Number
========|===============|============|=======

and a classes defined as:

public class Person
{
    ContactNumber homePhone;
    ContactNumber workPhone;
}

public class ContactNumber
{
    string Number;
}

How would I define my HBM mapping/s for the Person and ContactNumber class so that Person.homePhone is mapped to the corresponding row in the [ContactNumbers] table with the FK observed, and [ContactNumbers].[NumberType] equal to "HOME"? ([NumberType] is "WORK" for Person.workPhone.)

Already spent a good deal of the day just looking into this, and I couldn't find a solution just yet.

A: 

You cannot map single entity / instance to multiple rows and vice versa.

What you can do is do this:

class Person
{
  public IList<ContactNumber> ContactNumbers { get; set; }
}

And then map the ContactNumbers class as a collection / ony-to-many association. The PersonID column is listed as a foriegn key so I assume there is a person table?

Torkel
Yup, there is. This is what I thought of first, but was hoping that there was a solution that wouldn't have me knocking on my designer's door to change the code. ;)
Richard Neil Ilagan