We a mant-to-many relationship modeled in the database (with a bridge table) between Student and Professor, but in our entites we want to model it as a one-to-many relationship i.e. a Student has one Professor.
Here is our attempt, but it doesnt work:
protected StudentMap()
{
Id(x => x.Id);
Map(x => x.Name);
Join("student_professor_selected", m =>
{
m.KeyColumn("student_professor_selected_key");
m.References(x => x.Professor);
});
}
Join is something completely different. It is used to put parts of a class into another table (one-to-one).
You just map a many-to-many relation from professor to student, it is always a simple List in C#.
It’s not possible to map it as a single ending reference from student to professor. But you could map a list of professors in a private property and implement a Professor property which just returns the first element: