Question

I've got what I think is a simple query but cannot for the life of me figure out how to do this using nhibernate 2.X.

Suppose I have this simple SQL Query that joins on the same table, how can I return a list of objects?

select   primary_details.*, 
         secondary_details.*, 
from     details primary_details 
         JOIN details secondary_details 
         ON primary_details.ID = secondary_details.ID;

Now obviously there is other criteria that would be applied so I don't get a result set of the same data duplicated, but I've simplified it for my question.

My details Domain and mappings work fine if I just do a Select from details, but what I need is a result set with the data joined so I can chart a column from primary_details against secondary_details.

Any ideas would be appreciated. Even if it the solution is to handle this outside of nhibernate somehow.

Dumbed down Mapping File:

<class name="details" table="details" lazy="true" schema-       
action="none">
<id name="ID">
  <column name="ID" sql-type="varchar(32)" />
</id>
<property name="Name">
  <column name="Name" not-null="false" />
</property>
<property name="Value">
  <column name="laboratory_id" not-null="false" />
</property>
</class>

Cheers

No correct solution

OTHER TIPS

Try this:

var session.CreateSQLQuery("select {pd.*}, {sd.*}, from details pd JOIN details sd ON pd.ID = sd.ID").AddEntity("sd", typeof(details)).AddEntity("pd", typeof(details)).List<details>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top