c# - Multple Composite PrimaryKey reference as foreign key map in Fluent nHibernate -
this legacy table structure hence no schema modification possible.
patient ------- code - pk hospitalcode - pk - fk hospital.code hospitalgroup - pk - fk hospital.hospitalgroup other fields hospital ------- code - pk hospitalgroup - pk - fk hospitalgroup.code other fields department ------- code - pk hospitalcode - pk - fk hospital.code hospitalgroup - pk - fk hospitalgroup.code other fields diagnose ------- patientcode - pk - fk patient.code hospitalcode - pk - fk hospital.code hospitalgroup - pk - fk hospital.hospitalgroup departmentcode - pk - fk department.code other fields
the mapping looks following
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"); } }
how make fluent mapping such able
patient.diagnoselist[0].department.hospital.code
currently getting following exception
"identifier mapping has wrong number of columns: examples.firstproject.entities.diagnose type: component[department,patient]"
Comments
Post a Comment