views:

160

answers:

0

Hi!

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?