I have 2 entities- Classroom
and Section
, that I need help with NHibernate mapping. A Classroom
has a collection of Sections
. And the Section
has a reference back to its owner Classroom
.
On the code side:
public class Classroom
{
public int Id { get; set; }
public ISet<Section> Sections { get; set; }
}
public class Section
{
public int Id { get; set; }
public Classroom Classroom { get; set; }
}
On the database side:
CREATE TABLE Classroom (
ClassroomID int
)
CREATE TABLE ClassroomSection (
ClassroomID int,
SectionID int,
IsActive bit
)
CREATE TABLE Section (
SectionID
)
As seen above, even though this is a one-to-many mapping, there is a 3rd mapping table ClassroomSection
. Moveover this mapping table has some of its own fields, like IsActive
. I don't want to create an entity for ClassroomSection in my code because it doesn't have any domain logic. But I do want to have access to the fields in this table. Any help with bidirectional mapping is appreciated.
Thanks!