您好我正在寻找帮助将以下表映射到hibernate映射文件: schema image http://barry-jones.com/temp/sch2.jpg
我正在尝试在加载userVOs时用localCalendarGroups填充localCalandarGroups列表。我正在使用中间表(user_localCalendarGroup)来保留用户和localCalendarGroup ID
public class UserVO
{
public virtual int id { get; set; }
public virtual string name { get; set; }
public virtual string pass { get; set; }
public virtual string email { get; set; }
public virtual string level { get; set; }
public virtual List<LocalCalendarGroupVO> localCalendarGroups { get; set; }
}
public class LocalCalendarGroupVO
{
public virtual int id { get; set; }
public virtual string name { get; set; }
}
到目前为止,这是我的映射文件。如何让NHibernate知道中间表?
<class name="UserVO" table="tb_users" lazy="false">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<property name="pass" />
<property name="level" />
<property name="email" />
<property name="localCalendarGroups"/>
任何帮助,指点非常赞赏。
答案 0 :(得分:4)
我建议您使用IList而不是List来映射域类中的localCalendarGroups关联。这将启用延迟加载集合。这是UserVO类的映射文件:
<class name="UserVO" table="tb_users">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<property name="pass" />
<property name="level" />
<property name="email" />
<bag name="localCalendarGroups" table="user_localCalendarGroup">
<key column="userID" />
<many-to-many class="LocalCalendarGroupVO" column="calID" />
</bag>
</class>
相应的类定义:
public class UserVO
{
public virtual int id { get; set; }
public virtual string name { get; set; }
public virtual string pass { get; set; }
public virtual string email { get; set; }
public virtual string level { get; set; }
public virtual IList<LocalCalendarGroupVO> localCalendarGroups { get; set; }
}
答案 1 :(得分:0)