Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NHibernate-使用subselect中集合的属性_C#_Nhibernate_Hql - Fatal编程技术网

C# NHibernate-使用subselect中集合的属性

C# NHibernate-使用subselect中集合的属性,c#,nhibernate,hql,C#,Nhibernate,Hql,我有休闲地图: <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

我有休闲地图:

<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>
当我创建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设置为a%

我得到以下QueryException:

无法解析属性:EntityId of:Prayon.Entities.LocalizedProperty [来自a国,从LocalizedProperty x中选择PropertyValue 其中x.EntityId=a.Id,x.PropertyName='Name'和x.LocalizedEntityClass='Prayon.Entities.Country' x.CultureName='de'取1,如:val]

我希望有人能帮助我设置hql。

如何:

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

任何类型都有两个特殊的属性id和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
我不是100%确定以上是正确的,因为我不知道你到底在做什么。我认为,讨论一下你是否真的需要进行某种本地化是件好事


尽管如此,我还是非常确定.id和.class是解决您当前挑战的关键。

这给了我一个类型不匹配的例外,附带一条消息:二进制逻辑运算符的左侧和右侧不兼容[Object:Prayon.Entities.Country]:-
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
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