我有一个表填充查询,它必须获取所有引用实体。
我有客户:
public class Client
{
public virtual int Id { get; set; }
public virtual ICollection<Address> Addresses { get; protected set; }
public virtual Address CurrentAddress { get; set; }
}
地址
public class Address
{
public virtual int Id { get; set; }
public virtual string Address1 { get; set; }
public virtual string City { get; set; }
public virtual string ZipCode { get; set; }
}
和DB图:
我想让Linq的所有用户地址到Nhibernate:
ClientRepository.Where(x => x.Id == clientId).SelectMany(c => c.Addresses ).Where(x => x.Address1.Contains("Comp")).ToList();
但我得到了这个问题:
SELECT TOP (20 /* @p0 */) Id31_,
Address2_31_,
Address3_31_,
City31_,
ZipCode31_
FROM (select address2_.Id as Id31_,
address2_.Address1 as Address2_31_,
address2_.Address2 as Address3_31_,
address2_.City as City31_,
address2_.ZipCode as ZipCode31_,
ROW_NUMBER() OVER( ORDER BY address2_.Address1) as __hibernate_sort_row
from CLIENTS client0_
inner join AddressToClient addresshis1_
on client0_.Id = addresshis1_.ClientId
inner join ADDRESSES address2_
on addresshis1_.AddressId = address2_.Id
where address2_.Id = 2 /* @p1 */) as query
WHERE query.__hibernate_sort_row > 0 /* @p2 */
ORDER BY query.__hibernate_sort_row
EDITED 我的存储库:
/// <summary>
/// Gets the repository query.
/// </summary>
/// <value>The repository query.</value>
protected override IQueryable<Client> RepositoryQuery
{
get
{
return Session.Query<Client>();
}
}
id = address2_.Id
的查询过滤器不是客户端ID。
为什么搜索按地址ID而非客户端显示?
答案 0 :(得分:4)
尝试将两个“x”变量名中的一个更改为不同的名称。当前的NHibernate发行版中存在一个可能导致此问题的错误。