nHibernate 查询参考表
我在 fluid-nhibernate 和标准方面遇到问题。
我有以下设置。
class AMap : ClassMap<A>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class BMap : ClassMap<B>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class CMap : ClassMap<C>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class ConnectionMap : ClassMap<Connection>
{
References(x => x.A);
References(x => x.B);
References(x => x.C);
}
Connection 类是数据库中的一个视图,其背后有一些逻辑,但在这里并不那么重要。
但是当我尝试执行以下操作时,
session.CreateCriteria<A>()
.CreateAlias("Connection", "c")
.CreateAlias("c.B", "b")
.Add(Expression.Eq("b.Id", 55))
.List<A>() as List<A>;
Nhibernate 首先选择
select this_.Id as y0_,
...(more A properties)
b.Id as b0_,
...(more B properties)
c.AId as c0_,
c.BId as c1_,
c.Cid as c2_
from A this_ inner join
Connection c on this_.Id = c.A.Id
inner join c.B b on b.Id = c.B.Id
where b.Id = 55
我想要的。但在选择之后,它会继续选择连接“c”引用的其他实体。
有没有办法告诉 nHibernate 不要在结果中包含 c 的列(没有投影)?或者我必须使用 hql 来进行此查询吗?
I'm having a problem with fluent-nhibernate and criteria.
I have the following setup.
class AMap : ClassMap<A>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class BMap : ClassMap<B>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class CMap : ClassMap<C>
{
Id(x => x.Id);
...
HasMany<Connection>(x => x.Connection).Inverse().ReadOnly();
}
class ConnectionMap : ClassMap<Connection>
{
References(x => x.A);
References(x => x.B);
References(x => x.C);
}
The Connection class is a view in the database that has some logic behind it that is not so important here.
But when I try to do the following
session.CreateCriteria<A>()
.CreateAlias("Connection", "c")
.CreateAlias("c.B", "b")
.Add(Expression.Eq("b.Id", 55))
.List<A>() as List<A>;
Nhibernate starts by selecting
select this_.Id as y0_,
...(more A properties)
b.Id as b0_,
...(more B properties)
c.AId as c0_,
c.BId as c1_,
c.Cid as c2_
from A this_ inner join
Connection c on this_.Id = c.A.Id
inner join c.B b on b.Id = c.B.Id
where b.Id = 55
which is what I want. But after that select it goes on by selecting the other entities that Connection "c" references.
Is there a way to tell nHibernate not to include c's columns in the result (without projection)? Or do I have to use hql for this query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论