2009-06-10 258 views
0

我有2个实体 - ClassroomSection,我需要帮助NHibernate映射。 A Classroom收集了Sections。而Section有一个参考返回给它的主人ClassroomNHiberate映射问题

在代码侧:

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。移动此映射表有一些自己的字段,如IsActive。我不想在我的代码中为ClassroomSection创建实体,因为它没有任何域逻辑。但我确实想访问此表中的字段。任何帮助双向映射表示赞赏。

谢谢!

回答

0

听起来像ClassroomSection是一个值对象而不是实体,是正确的吗?

+0

我不认为ClassroomSection是什么。它只是Classroom和Section之间的映射表。 – 2009-06-10 18:00:24

0

发表您希望能够访问IsActive的一些示例代码。

Ayende的最新信息可能给一些提示,你想实现什么:http://ayende.com/Blog/archive/2009/06/10/nhibernate-ndash-query-only-properties.aspx

+0

你问一个很好的问题。我不知道为什么我以前没有考虑过这个问题。我应该如何访问IsActive?我可以让它住在Section实体中。然后,我可以在Section映射中对ClassroomSection执行。但科室本身有一个IsActive领域。看起来我毕竟可能必须创建一个ClassroomSection实体。我不认为有这个问题。 – 2009-06-12 15:17:17