通过 HQL 在 Nhibernate 中选择
我有一些映射:
<class entity-name="Person" table="table1">
<id column="Id" type="long" name="Id"/>
<set name="Address">
<key column="Person_id"/>
<one-to-many class="Address"/>
</set>
<property column="Id" name="Id" type="long"/>
<property column="Last_Name" name="LastName" type="string"/>
<property column="First_Name" name="FirstName" type="string"/>
<property column="Education" name="Education" type="string"/>
</class>
<class entity-name="Address" table="table2">
<id column="Id" type="long" name="Id"/>
<property column="Id" name="Id" type="long"/>
<property column="City" name="City" type="long"/>
<property column="Street" name="Street" type="string"/>
<property column="number" name="number" type="string"/>
</class>
这是我的 HQL 查询 hbm= "from person p join fetch p.Address WHERE p.id in (:ids)"
但现在我从两个表(地址和人员)中获取 select * 我需要 HQL 来返回人员的姓氏、名字以及包含 City 、 Street 的地址集合
我如何在地址字段上添加条件?
I have some mapping:
<class entity-name="Person" table="table1">
<id column="Id" type="long" name="Id"/>
<set name="Address">
<key column="Person_id"/>
<one-to-many class="Address"/>
</set>
<property column="Id" name="Id" type="long"/>
<property column="Last_Name" name="LastName" type="string"/>
<property column="First_Name" name="FirstName" type="string"/>
<property column="Education" name="Education" type="string"/>
</class>
<class entity-name="Address" table="table2">
<id column="Id" type="long" name="Id"/>
<property column="Id" name="Id" type="long"/>
<property column="City" name="City" type="long"/>
<property column="Street" name="Street" type="string"/>
<property column="number" name="number" type="string"/>
</class>
It's my HQL query
hbm= "from person p join fetch p.Address WHERE p.id in (:ids)"
but now I get select * from both tables(Address and Person)
I need HQL that retern LastName,FirstName of person and collection of Addresses that contains City , Street
I haw I add conditions on Address fields??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加 Select p 以仅返回人员。
为Address 添加别名,以便可以在where 子句(条件)中使用它。
Add Select p to only return Person.
Add an alias to Address so that you can use it in the where clause (conditions).
这个查询怎么样?
结果集合包含对象数组,然后:
What about this query?
The result collection contains object arrays then: