views:

31

answers:

1

I have a legacy system I'm working on and there is a particular relationship I'm having trouble with.

The issue is that I need to relate Patient to HL7EPICareMeds... the relationship above isn't working, of course.

From the table perspective, here is what I have

Patient:
PatientId : int, PK
ClinicPatientId : varchar --- not unique

HL7EPICareMeds:
Id: : int, PK
ClinicPatientId : varchar
MedName: varchar
AdminTime : datetime

Should I reuse the Patient table as an association table between ClinicPatientIDs and PatientId?

[ActiveRecord]
public class Patient : RecordBase<Patient>
{
    [PrimaryKey("PatientId", Generator=PrimaryKeyType.Native)]
    public int? Id
    {
        get { return _id; }
        set
        {
            _id = value;
        }
    }

    [HasAndBelongsToMany(Inverse = true, Lazy = true)]
    public IList<HL7EPICareMeds> Meds
    {
        get { return _meds; }
        set { _meds = value; }
    }
}

[ActiveRecord]
public class HL7EPICareMeds : RecordBase<HL7EPICareMeds>
{
    [PrimaryKey(Generator = PrimaryKeyType.Native)]
    public long Id
    {
        get { return _Id; }
        set
        {
            _Id = value;
        }
    }

    [Property("AdminTime")]
    public DateTime? AdministrationTime
    {
        get { return _AdministrationTime; }
        set { _AdministrationTime = value; }
    }

    [Property(NotNull = true,Update=false,Insert=false),
    ValidateLength(0, 20)]
    public string ClinicPatientId
    {
        get { return _ClinicPatientId; }
        set
        {
            _ClinicPatientId = value;
        }
    }

    [Property(NotNull = true),
    ValidateLength(0, 255)]
    public string MedName
    {
        get { return _MedName; }
        set
        {
            _MedName = value;
        }
    }

    [HasAndBelongsToMany()]
    public Patient Patient
    {
        get { return _patient; }
        set { _patient = value; }
    }
}
A: 

Look at the property-ref mapping element. This should do exactly what you need.

It's used to associate entities when the FK isn't necessarily a PK on the parent table.

Corey Coogan
Isn't the property-ref mapping only available in a one-to-many relation? Or perhaps its used for table-inheritance?
Marc