Skip to content

Instantly share code, notes, and snippets.

@NickBranstein
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save NickBranstein/3fd38620e869c044e64c to your computer and use it in GitHub Desktop.

Select an option

Save NickBranstein/3fd38620e869c044e64c to your computer and use it in GitHub Desktop.
NHibernate Many To Many
public class Classroom
{
public virtual int RoomNumber { get; set; }
public virtual IEnumerable<Student> Students { get; set; }
}
public class ClassroomMap : ClassMapping<Classroom>
{
public ClassroomMap()
{
Bag(x => x.Students, m => m.Table("StudentClassroom"), map => map.ManyToMany(p => p.Class(typeof (Student))));
}
}
public class Student
{
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual IEnumerable<Classroom> Classrooms { get; set; }
}
public class StudentMap : ClassMapping<Student>
{
public StudentMap()
{
Bag(x => x.Classrooms, m => m.Table("StudentClassroom"), map => map.ManyToMany(p => p.Class(typeof(Classroom))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment