0

I have two different entities, I need to join them based on a common entity property between them, but there's no path to get from the entity the Criteria is created on to the other one! Please help.

Thanks


--Edit--

Sorry, maybe my question was not clear.

I have the following Entities:

class A
{
    string Text {get;set;}
}
class B 
{
    string Text {get;set;}
}
class C
{
    string Text {get;set;}
    B B_Object_1 {get;set;}
}
class D
{
    A A_Object {get;set;}
    B B_Object_2 {get;set;}
}

what I'm trying to do is creating a criteria on D entity, yet, I need to join it with C entity , and the join condition is D.B_Object_2 == C.B_Object_1

because on projection, or what I need to be selected as a results contains: D.A_Object.Text and C.B_Object_1.Text based on my join condition above.

Can this be done using Criteria or with the assistance of DetachedCriteria?

Thanks

Ruba
  • 867
  • 3
  • 11
  • 19
  • Can you be more specific, give us an example, show use the entities involved, etc? At the moment, this question is a bit too vague to answer. – Daniel Schilling Sep 03 '13 at 15:34
  • That's much better. Are you able to express the query you are shooting for using SQL? – Daniel Schilling Sep 04 '13 at 12:41
  • I need to Join D and C based on this condition "D.B_Object_2 == C.B_Object_1", and then select Data from D, and C.B_Object_1 at the same time. – Ruba Sep 04 '13 at 14:32

1 Answers1

0

I guess it's not possible. At least did not find any neat solution. But there are two workarounds:

  1. Query only properties. Not sure Criteria API could handle this, but HQL defenitely does.
  2. Plain old SQL-queries - session.CreateSQLQuery().
Jury Soldatenkov
  • 427
  • 1
  • 6
  • 12