代码之家  ›  专栏  ›  技术社区  ›  Rohit Agarwal

nhiberate映射问题

  •  0
  • Rohit Agarwal  · 技术社区  · 16 年前

    我有两个实体- Classroom Section ,我需要NHibernate映射的帮助。一 教室 收藏了 Sections . 以及 截面 找到了它的主人 教室 .

    在代码方面:

    public class Classroom
    {
        public int Id { get; set; }         
        public ISet<Section> Sections { get; set; } 
    }
    
    public class Section
    {
        public int Id { get; set; } 
        public Classroom Classroom { get; set; } 
    }
    

    在数据库方面:

    CREATE TABLE Classroom (
       ClassroomID int
    )
    
    CREATE TABLE ClassroomSection (
       ClassroomID int, 
       SectionID int,
       IsActive bit
    )
    
    CREATE TABLE Section (
       SectionID
    )
    

    如上所示,即使这是一个 一对多 映射,有第三个映射表 ClassroomSection . moveover这个映射表有一些自己的字段,比如 IsActive . 我不想在代码中为classroomsection创建实体,因为它没有任何域逻辑。但我确实想访问此表中的字段。感谢任何有关双向映射的帮助。

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  0
  •   Chance    16 年前

    听起来classroomsection是一个值对象而不是实体,对吗?

        2
  •  0
  •   Ben    16 年前

    发布一些您希望如何访问isactive的示例代码。

    Ayende的最新文章可能会给你一些提示,告诉你你想要完成什么: http://ayende.com/Blog/archive/2009/06/10/nhibernate-ndash-query-only-properties.aspx

    推荐文章