Here is the domain that I wish to have:
public class Person
{
public int Id { get; set; }
public IList<AcquiredCertificate> AcquiredCertificates { get; set; }
}
public class AcquiredCertificate
{
public Person Acquirer { get; set; }
public Certificate Certificate { get; set; }
public DateTime DateAcquired;
}
public class Certificate
{
public int Id { get; set; }
}
And this is the schema that I have:
CREATE TABLE People (
PersonId INT PRIMARY KEY
);
CREATE TABLE Certificates (
CertificateId INT PRIMARY KEY
);
CREATE TABLE CertificatesAcquiredByPeople (
PersonId INT,
CertificatedId INT,
DateAcquired DATETIME
);
It's a contrived schema and domain but it's pretty much the same as something that I am working with. I currently have it working by writing a 3rd domain entity to represent the CertificatesAcquiredByPeople table but that really seems strange to me.
How would I map this using NHibernate? I believe the component tag in the hbm file should do what I want, but I can't quite figure it out.
Is my domain out of whack because I have a DateAcquired property on my Certificate class? The date really is only a concern of a Person that has a certificate.
[Edit]
I've altered the domain model now to reflect that a new entity is needed. Now for the mapping do I need 3 (for each entity) mappings or can I do it with 2 (for Person and Certificate)?