开发者

Multi-table NHibernate query

开发者 https://www.devze.com 2023-03-17 05:59 出处:网络
I have an object graph that looks like this: class A () { int id; IEnumerable<B> bees; } class B() { int id;

I have an object graph that looks like this:

class A ()
{
   int id;
   IEnumerable<B> bees;
}

class B()
{
   int id;
   A a;
   C c;
}

class C()
{
   int id;
   D d;
   IEnumerable<B> bees;
}

class D()
{
   int id;
   IEnumerable<C> cees
}

What would be a sensible approach for constructing a query which:

returns a list o开发者_运维百科f A types, where they contain D down the chain with a particular id?

I'm using NH3, so can use any of the query techs. I've tried a couple of different approaches, but have hit seemingly dead ends in each case. I have a solution working with in memory collections - but obviously this is not ideal, I want the work done on the DB server.


select distinct a from A a
inner join a.bees b
inner join b.c c
where c.d.id = :theSearchDId

That is assuming that all the associations are bidirectional associations, and not unrelated associations (i.e. A.bees is the inverse association of B.a, etc.).

0

精彩评论

暂无评论...
验证码 换一张
取 消