Last active
August 29, 2015 14:05
-
-
Save NickBranstein/3fd38620e869c044e64c to your computer and use it in GitHub Desktop.
NHibernate Many To Many
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Classroom | |
| { | |
| public virtual int RoomNumber { get; set; } | |
| public virtual IEnumerable<Student> Students { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ClassroomMap : ClassMapping<Classroom> | |
| { | |
| public ClassroomMap() | |
| { | |
| Bag(x => x.Students, m => m.Table("StudentClassroom"), map => map.ManyToMany(p => p.Class(typeof (Student)))); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Student | |
| { | |
| public virtual string FirstName { get; set; } | |
| public virtual string LastName { get; set; } | |
| public virtual IEnumerable<Classroom> Classrooms { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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