This is a one-way, one-to-one mapping problem in NHibernate.
Student.cs
public class Student { public int ID { get; set; } public int Roll { get; set; } public int RegNo { get; set; } public string Name { get; set; } public StudentDetail StudentDetail { get; set; } }
StudentDetail.cs
public class StudentDetail { public int ID { get; set; } public string Father { get; set; } public string Mother { get; set; } }
How can I map these classes (what does the hbm mapping file look like) in the following one-to-one relationship?

Please read the classes and table carefully.
Where can I put the <many-to-one> in Student.hbm.xml or StudentDetail.hbm.xml ? If I put it in Student.hbm.xml , how can I match the StudentDetail.StudentID column because it is in a different table?
So this mapping:
<class name="Student" table="Student"> <id name="ID" column="ID"> <generator class="native"/> </id> ....... <many-to-one class="StudentDetail" name="StudentDetail" column="StudentID" unique="true" cascade="all" /> </class>
throws the following exception:
{"Invalid column name 'StudentID'."}
On the other hand, <many-to-one> cannot be placed in StudentDetail.hbm.xml . Coz, StudentDetail.cs does not contain any property of type Student .
Can I use the <one-to-one> -tag? If so, where should I place it in Student.cs or StudentDetail.cs ? And how to configure it?
nhibernate one-to-one
anonymous
source share