NHibernate-使用subselect中集合的属性
本文关键字:属性 集合 使用 subselect NHibernate- | 更新日期: 2023-09-27 18:20:58
我有闲置的映射:
<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创建一个select,它应该返回所有国家,并使用休耕的"正常"SQL select
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.Enties.LocalizedProperty[来自国家/地区a其中(从LocalizedProperty x中选择PropertyValue其中x.EntityId=a.Id,x.PropertyName="Name",x.LocalizedEntityClass="Prayon.Entitys.Country"和x.CultureName='de'take 1)类似:val]
我希望有人能帮助我如何设置我的hql。
任何"Any"-类型都有两个特殊的属性"id"answers"class",所以你应该能够用它们做一些事情,比如这个
from Country a
where (
select PropertyValue
from LocalizedProperty x
where x.Entity.id = a.Id
and x.PropertyName = 'Name'
and x.Entity.class = 'Prayon.Entities.Country'
and x.CultureName = 'de' take 1)
Like :val
我不能百分之百肯定以上是正确的,因为我看不出你在做什么。我认为,讨论一下你是否真的需要进行本地化是件好事。
尽管如此,我确信.id和.class是解决您当前挑战的关键。
怎么样:
from Country a
where (
select PropertyValue
from LocalizedProperty x
where x.Entity = a
and x.PropertyName = 'Name'
and x.CultureName = 'de' take 1)
Like :val