2010-02-26 122 views
0

不知道我在这里用NHibernate不正确地做什么。我有两个映射文件映射到两个表。我可以通过映射将数据插入到数据库中,但调用下面的代码将返回0,即使我可以看到使用正确的外键填充表中的子行。这是一个懒加载问题?谢谢。NHibernate集合不加载数据,但数据插入数据库

var result = session.Get<AnnualReport>(annualReport.ReportID); 
Assert.AreEqual(result.MonthlyReports.Count, 1); 

这是我的映射文件。

年报类

<joined-subclass name="AnnualReport" extends="Report" table="AnnualReports" > 

<key column="ReportID"/> 

<property name="MonthlySendDate" /> 

<bag name="MonthlyReports" lazy="true" inverse="true"> 
    <key column="ReportID" /> 
    <one-to-many class="MonthlyReport"/> 
</bag> 

<many-to-one name="Client" column="ClientID" not-null="true" /></joined-subclass> 

MonthlyReport类

<joined-subclass name="MonthlyReport" extends="Report" table="MonthlyReports"> 

<key column="ReportID"/> 
<property name="SentDate" /> 

<many-to-one name="AnnualReport" class="AnnualReport" column="AnnualReportID" not-null="true"/> 

<bag name="MarketReports" cascade="all"> 
    <key column="MonthlyReportID" /> 
    <one-to-many class="MarketReport"/> 
</bag> 

+0

它应该是多对多的关系吗? – Steve 2010-02-26 11:32:45

回答

0

感谢您的回应史蒂夫,我设法虽然弄明白。外键映射不正确..下面的问题解决了问题,现在集合正在加载。

<bag name="MonthlyReports" lazy="true" inverse="true"> 
    <key column="AnnualReportID" /> 
    <one-to-many class="MonthlyReport"/> 
</bag>