Hi all,

I am currently using NHibernate 2.0.1 and I have a problem with
projections.

I have 2 tables:
- Person (id, fname, lname, dob, gender, address)
- Gender (id, name)
Person.gender = Gender.id

I would like to use projections to only return Person.id and
Person.gender, so here is my code:

            DetachedCriteria criteria = DetachedCriteria.For<Person>()
                .SetProjection(Projections.ProjectionList()
                    .Add(Projections.Property("Id"), "Id")
                    .Add(Projections.Property("Gender"), "Gender"))
                .SetResultTransformer
(NHibernate.Transform.Transformers.AliasToBean(typeof(Person)));

I call this code with my Nhibernate session manager to return a
IList<Person>.

When I launch it, NHibernate generates the following SQL query:
SELECT this_.id as y0_, this_.gender as y1_ FROM Person this_;

But, it also generates
SELECT gender0_.id as id29_0_, gender0_.name as name29_0_ FROM Gender
gender0_ WHERE gender0_....@p0;
for each Person.

I have <many-to-one name="Gender" fetch="join" class="test.Gender,
test" column="gender"/> in the mapping file of Person.

So, what can I do to have only one SQL query that will actually create
an instance of a Gender object for each Person.gender? Because right
now, with this code, Person.gender only contains the foreign key of
the Gender table; it should contain a Gender object.

Thanks in advance for your help.

Cheers,

Nasedo47

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to