nHibernate 查询参考表

发布于 2024-08-25 05:02:46 字数 1345 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文