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 uniqueHL7EPICareMeds:
Id: : int, PK ClinicPatientId : varchar MedName: varchar AdminTime : datetimeShould 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
 开发者_Python百科       {
            _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; }
    }
}
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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论