从一组属性我有休耕映射:NHibernate的 - 使用子查询
<class name="Country" table="Country" lazy="false" >
<cache usage="read-write"/>
<id name="Id" column="Id" type="Guid">
<generator class="assigned"/>
</id>
<property name="Name" column="Name" type="String" length="50" not-null="true" unique="true" />
<set name="LocalizedProperties" where="LocalizedEntityClass = 'Prayon.Entities.Country'" cascade="delete">
<key column="EntityId" foreign-key="none" />
<one-to-many class="LocalizedProperty" />
</set>
</class>
LocalizedProperty声明如下:
<class name="LocalizedProperty" table="LocalizedProperty">
<cache usage="read-write"/>
<id name="Id" column="Id">
<generator class="guid.comb"/>
</id>
<property name="CultureName" not-null="true"/>
<property name="PropertyName" not-null="true"/>
<property name="PropertyValue" not-null="true"/>
<any id-type="Guid" name="Entity">
<column name="LocalizedEntityClass" not-null="true"/>
<column name="EntityId" not-null="false"/>
</any>
</class>
现在,我尝试创建一个选择与HQL应全部归还国家,与下面的“正常”SQL-选择
select *
from Country a
where (
select top 1 PropertyValue
from LocalizedProperty x
where x.EntityId = a.Id
and x.PropertyName = 'Name'
and x.LocalizedEntityClass = 'Prayon.Entities.Country'
and x.CultureName = 'de')
Like 'a%'
当我创建hql像
from Country a
where (
select PropertyValue
from LocalizedProperty x
where x.EntityId = a.Id
and x.PropertyName = 'Name'
and x.LocalizedEntityClass = 'Prayon.Entities.Country'
and x.CultureName = 'de' take 1)
Like :val
和参数val设为%
我得到以下QueryException
:中ENTITYID:Prayon.Entities.LocalizedProperty [A国,其中
未能解决物业(选择从的PropertyValue LocalizedProperty X 其中x.EntityId = a.Id和x.PropertyName = '名称' 和x.LocalizedEntityClass = 'Prayon.Entities.Country' 和x.CultureName = '日' 取1)像:VAL ]
我希望有人能帮助我如何设置我的HQL。
很好,它与你的语句一起工作1:1。谢谢! – BennoDual