这是一个遗留的表结构,因此无法进行架构修改。
Patient
-------
Code - PK
HospitalCode - PK - FK with Hospital.Code
HospitalGroup - PK - FK with Hospital.HospitalGroup
Other fields
Hospital
-------
Code - PK
HospitalGroup - PK - FK with HospitalGroup.Code
Other fields
Department
-------
Code - PK
HospitalCode - PK - FK with Hospital.Code
HospitalGroup - PK - FK with HospitalGroup.Code
Other fields
Diagnose
-------
PatientCode - PK - FK with Patient.Code
HospitalCode - PK - FK with Hospital.Code
HospitalGroup - PK - FK with Hospital.HospitalGroup
DepartmentCode - PK - FK with Department.Code
Other fields
映射如下所示
public class PatientMap : ClassMap<Patient>
{
public PatientMap()
{
CompositeId()
.KeyProperty(x => x.Id, "ID")
.KeyReference(x => x.Hospital, "Hospital_id", "HospitalGroup_id")
.KeyReference(x => x.HospitalGroup, "HospitalGroup_id");
Map(x => x.Name);
}
}
public class HospitalMap : ClassMap<Hospital>
{
public HospitalMap()
{
CompositeId()
.KeyProperty(x => x.Id, "ID")
.KeyReference(x => x.HospitalGroup, "HospitalGroup_id");
Map(x => x.Name);
}
}
public class HospitalGroupMap : ClassMap<HospitalGroup>
{
public HospitalGroupMap()
{
Id(x => x.Id).Column("ID");
Map(x => x.Name);
}
}
public class DepartmentMap : ClassMap<Department>
{
public DepartmentMap()
{
CompositeId()
.KeyProperty(x => x.Id, "ID")
.KeyReference(x => x.Hospital, "Hospital_id", "HospitalGroup_id")
.KeyReference(x => x.HospitalGroup, "HospitalGroup_id");
Map(x => x.Name);
}
}
public class DiagnoseMap : ClassMap<Diagnose>
{
public DiagnoseMap()
{
CompositeId()
//.KeyReference(x => x.Hospital, "Hospital_id", "HospitalGroup_id")
//.KeyReference(x => x.HospitalGroup, "HospitalGroup_id")
.KeyReference(x => x.Department, "Department_id", "Hospital_id", "HospitalGroup_id")
.KeyReference(x => x.Patient, "Patient_id", "Hospital_id", "HospitalGroup_id");
}
}
如何制作流畅的地图,以便我能够获得
Patient.DiagnoseList[0].Department.Hospital.Code
目前我收到以下异常
"identifier mapping has wrong number of columns: Examples.FirstProject.Entities.Diagnose type: component[Department,Patient]"