Hallo,
I have this class hirachy:
class Book{
public virtual long Id{get;set;}
public virtual Student Student{get;set;}
public virtual string WantedProperty1{get;set;}
public virtual string WantedProperty2{get;set;}
}
class Student{
public virtual long Id{get;set;}
public virtual Professor Professor{get;set;}
}
class Professor{
public virtual long Id{get;set;}
public virtual string PersonalNumber{get;set;}
}
The Mapping looks like this:
<class name "Book">
<id name="Id" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="Student" column=StudentId" />
<class />
<class name "Student">
<id name="Id" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="Professor" column="PersonalNumber" property-
ref="PersonalNumber" not-null="true" />
<class />
<class name "Professor">
<id name="Id" unsaved-value="0">
<generator class="native" />
</id>
<property name="PersonalNumber" not-null="true" />
<class />
Now I try the following criteria:
session.CreateCriteria<Book>()
.CreateCriteria("Student")
.CreateCriteria("Professor")
.Add(Restrictions.IdEq(professorId))
.List<Book>()
The Criteria returns the correct result but it selects all properties
of student and professor which causes other subselects for
childobjects. The childobjects are lazy many-to-one relations but
because of using property-ref and not-found=ignore no proxies will be
created. At the moment I'm solving this problem with projection:
session.CreateCriteria<Book>()
.CreateCriteria("Student")
.CreateCriteria("Professor")
.Add(Restrictions.IdEq(professorId))
.SetProjection(
Projections.Property("WantedProperty1").As("WantedProperty1"),
Projections.Property("WantedProperty2").As("WantedProperty2"))
.SetResultTransformer(Transformers.AliasToBean(typeof(Book)))
.List<Book>()
is there a better way to select only the wanted object?
--
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.