[英]NHibernate query on one-to-many
I got a Client entity related to n network domain accounts. 我有一个与n个网络域帐户相关的客户实体。
Client:
IList<DomainInfo> domainInfo;
DomainInfo:
string domain;
string username;
The mapping of Client.hbm.xml contains: Client.hbm.xml的映射包含:
<bag name="domainInfo" cascade="all" lazy="false">
<key column="client"/>
<one-to-many class="Kardex.CMS.Domain.Model.Client.DomainInfo"/>
</bag>
The mappinf of DomainInfo.hbm.xml does NOT contain a many-to-one mapping to Client. DomainInfo.hbm.xml的mappinf不包含到客户端的多对一映射。
When I insert Client entities with domain info elements into the database, everything works fine. 当我将带有域信息元素的客户端实体插入数据库时,一切正常。 Each domain info entry contains the "client"-column mapped to the right client.
每个域信息条目都包含映射到正确客户端的“客户端”列。
Now I want to query the user with a certain network domain and username: 现在,我要查询具有特定网络域和用户名的用户:
clients = session.CreateQuery("from Client c where c.domainInfo.username = :winuser and c.domainInfo.domain = :windomain")
.SetParameter("winuser", "john_doe")
.SetParameter("windomain", "domain123")
.List<Client>();
But I get an exception: 但我有一个例外:
illegal attempt to dereference collection [client0_.id.domainInfo] with element
property reference [username]
I also tried an INNER JOIN, but then I get another exception: 我也尝试了INNER JOIN,但是随后又出现另一个异常:
from Client c inner join c.domainInfo d where d.username = :winuser and d.domain = :windomain
throws 抛出
Could not execute query[SQL: SQL not available]
This should be a simple task I guess? 我猜这应该是一个简单的任务吗? What could be wrong here?
这有什么问题吗?
Thank you in advance! 先感谢您!
修复:
select c from Client c left join c.domainInfo d where d.username = :winuser and d.domain = :windomain
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.