一对多/多对一NHibernate映射
||
我有一个带有少数实体以及它们之间各种关系的应用程序。但是,我的一对多关系出了点问题,我不知道该怎么办。当我尝试从关系的“一个”一侧导航到“许多”一侧时,我会“非法访问加载收藏集”。对于我的应用程序中的所有一对多关系,都会发生这种情况。
例如,一个客户有多个帐户
从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中最简单的关系类型,我无法理解。我有大量的多对多关系,而没有看到这个问题。
没有找到相关结果
已邀请:
0 个回复