NHibernate - 在Property元素的Formula属性中选择查询不起作用

时间:2010-07-07 06:20:20

标签: nhibernate fluent-nhibernate nhibernate-mapping

我是NHibernate的新手。 我在我的hbm文件中使用以下属性元素......

<property name="CountryId" length="4" />
<property name="CountryForCustomer"
              formula="(SELECT *
                            FROM SystemCountry  
                            WHERE SystemCountry.CountryId = CountryId)" />

在这里,我试图从另一个表中的CountryId获取Country详细信息。

属性“CountryForCustomer”属于自定义类型“SystemCountry”。

但是公式中的这个查询无效。所以有人请帮我解决这个问题。

提前致谢....

2 个答案:

答案 0 :(得分:2)

不应该

SELECT SystemCountry.Country FROM SystemCountry WHERE...

因为*会从查询中返回多个列

编辑如果您想要返回整个对象,那么property元素不是您的朋友。你想要做的是看多对一元素,注意这只是一种方法。

<many-to-one name="CmsTemplate" column="TemplateId" ..

e.g。 herehere

答案 1 :(得分:0)

公式映射不会从数据库中映射其值,而是从会话中加载的数据集中映射其值