NHibernate Classmapping-based Manytomany (many-to-many configurations)

Source: Internet
Author: User

NHibernate Classmapping-based Manytomany (many-to-many configuration) entity classes
public class Library{    public virtual int Id { get; set; }    public virtual string Name { get; set; }    public virtual IList<Book> Books { get; set; }    public Library()    {        Books = new List<Book>();    }}public class Book{    public virtual int Id { get; set; }    public virtual string Name { get; set; }    public virtual IList<Library> Libraries { get; set; }    public virtual IList<BookLevel> BookLevel { get; set; }    public Book()    {        Libraries = new List<Library>();        BookLevel = new List<BookLevel>();    }}public class BookLevel{    public virtual int Id { get; set; }    public virtual string Name { get; set; }    public virtual IList<Book> Book { get; set; }    public BookLevel()    {        Book = new List<Book>();    }}
Classmapping Mapping class
public class librarymap:classmapping<library>{Public Librarymap () {Lazy (false);        Table ("Library"); Id (L = = L.id,map = {map. Column ("id"); Map. Generator (generators.identity);        }); Property (x = x.name, map = map.        Column ("LibraryName")); This. Bag (x = x.books, map = = map.            Table ("Book_library"); Map.            Cascade (Cascade.all); Map.            Inverse (false); Map.            Lazy (Collectionlazy.lazy); Map. Key (key = key).        Column ("LibraryID"));    }, M = m.manytomany (x = X.column ("BookId"));        }}public class bookmap:classmapping<book>{Public Bookmap () {Lazy (false);        Table ("book"); Id (L = = l.id, map = {map. Column ("id"); Map. Generator (generators.identity);        }); Property (x = x.name, map = map.        Column ("BookName")); This. Bag (x = x.libraries, map = = map.            Table ("Book_library"); Map. Cascade (Cascade.All); Map.            Inverse (false); Map.            Lazy (Collectionlazy.lazy); Map. Key (key = key).        Column ("BookId"));        }, M = M.manytomany (X=>x.column ("LibraryID"))); This. Bag (x = x.booklevel, map = = map.            Table ("Book_level"); Map.            Cascade (Cascade.all); Map.            Inverse (false); Map.            Lazy (Collectionlazy.lazy); Map. Key (key = key).        Column ("BookId"));    }, M = m.manytomany (x = X.column ("Levelid"));        }}public class booklevelmap:classmapping<booklevel>{Public Booklevelmap () {Lazy (false);        Table ("Booklevel"); Id (L = = l.id, map = {map. Column ("id"); Map. Generator (generators.identity);        }); Property (x = x.name, map = map.        Column ("LevelName")); This. Bag (x = x.book, map = = map.            Table ("Book_level"); Map.            Cascade (Cascade.all); Map.            Inverse (false); Map.      Lazy (Collectionlazy.lazy);      Map. Key (key = key).        Column ("Levelid"));    }, M = m.manytomany (x = X.column ("BookId")); }}

NHibernate Classmapping-based Manytomany (many-to-many configurations)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.