2010-02-26 121 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>