我有一个应用程序,其中包含少数几个实体和各种关系。但是,我的一对多关系出了问题,我无法弄清楚是什么。当我尝试从关系的“一方”导航到“多方”时,我得到'非法访问加载集'。这适用于我的应用程序中的所有一对多关系。
例如,客户有多个帐户
来自Customer.hbm.xml:
<bag name="Accounts" mutable="true" inverse="true" cascade="save-update">
<key>
<column name="Customer_Id" />
</key>
<one-to-many class="Account" />
</bag>
来自Account.hbm.xml:
<many-to-one class="Customer" name="Customer" not-null="true">
<column name="Customer_Id" />
</many-to-one>
在代码中,如果我说:
var accounts = customer.Accounts.AsEnumerable();0);
我得到“非法访问加载集合”。
同样,帐户有很多BillingDetails:
来自Account.hbm.xml:
<bag name="BillingDetails" mutable="true" inverse="true" cascade="save-update">
<key>
<column name="Account_Id" />
</key>
<one-to-many class="BillingDetail" />
</bag>
来自BillingDetails.hbm.xml:
<many-to-one class="Account" name="Account" not-null="true">
<column name="Account_Id" />
</many-to-one>
我无法理解为什么当我尝试访问客户帐户时,客户帐户不会延迟加载。同样,当我尝试访问帐户结算明细时,不会加载帐户结算明细。这应该是NHibernate中最简单的关系类型,我无法做到正确。在没有看到这个问题的情况下,我有多达多对多的关系。