NHibernate 基於 ClassMapping 的 ManyToMany(多對多配置)

來源:互聯網
上載者:User

標籤:lib   set   virt   ssm   lse   rar   nat   tor   int   

NHibernate 基於 ClassMapping 的 ManyToMany(多對多配置)實體類
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 映射類
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 的 ManyToMany(多對多配置)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.