I have a class that contains a collection that maps to a many-to-many database relationship using Fluent Nhibernate. The mapping is shown below:
Table("Book");
Id(x => x.Id);
Map(x => x.Title);
Map(x => x.NumberOfPages);
HasManyToMany(x => x.Authors)
.Cascade.AllDeleteOrphan()
.Table("BookAuthor")
.ParentKeyColumn("BookId")
.ChildKeyColumn("AuthorId");
Then I get an instance of this class and add the item to the authors collection using the following code:
var book = session.CreateCriteria(typeof(Book)).UniqueResult<Book>();
Author author = new Author {Name="Phil Moran",Age=51};
book.Authors.Add(author);
session.SaveOrUpdate(book);
, Nhibernate BookAuthor, , , , . ? , , , " " (BookAuthor) - . ?