The code that I use to generate the ICriteria:
ICriteria criteria = Session.CreateCriteria(typeof
(Person), "pers");
DetachedCriteria sub = DetachedCriteria.For<PersonAddress>
("persAddr");
sub.Add(Expression.Conjunction()
.Add(Expression.Like("persAddr.State", "MA"))
.Add(Expression.EqProperty("persAddr.PersonID",
"pers.PersonID")));
sub.SetProjection(Projections.Id());
criteria.SetResultTransformer(new
NHibernate.Transform.DistinctRootEntityResultTransformer());
retObject = criteria.List<Person>() as List<Person>;
Many thanks in advance
On Nov 7, 11:05 am, fknebels <fkneb...@gmail.com> wrote:
> FetchMode just adds an outer join to the query which will result in a
> Cartesian project which I definitely don't want. The SQL that is
> generated is exactly what I want. I have all the fields for everyobjectin theobjectgraph. I thought that the RootEntityTransformer
> would then populate the entireobjectgraph with actuallyobjectand
> not proxies, but when I iterate on the a one to many relationship, I
> see eachobjectin the graph calling out to sql server. I shouldn't
> need other techniques because the generated SQL returns all the fields
> I need. That's the whole point of writing this query and not just
> walking through everyobject.
>
> On Nov 6, 5:15 pm, Jason Meckley <jasonmeck...@gmail.com> wrote:
>
> > if you want to select the data you need to set the fetch mode, not the
> > join mode. however you may find that loading everything in a single
> > query may besub-optimal. you will end up with a Cartesian result set
> > (lot of duplicated data). If that is the case you could try other
> > techniques: ado.net batching (this may only apply to writes, not
> > reads), multi-queries,sub-select batching, filters. Even though you
> > execute multiple remote db calls, the results sets are unique and the
> > throughput could increase.
>
> > also, if your collections use a List instead of a Set you may get
> > duplicate items in the collections. A Set is the only collection that
> > ensure uniqueness.
>
> > On Nov 6, 4:37 pm, fknebels <fkneb...@gmail.com> wrote:
>
> > > I've got a iCriteria query that joins 7 different tables. The SQL it
> > > generates is exactly what I want. I thought I would be able to
> > > populate the entireobjecttree from this query, but as I iterate over
> > > child objects I see queries getting sent to SQL server using NHProf.
> > > How do I get this ICriteria to load the entireobjecttree? This is
.SetFetchMode("TableX", FetchMode.Join)
to your Criteria.So you can control when the whole object tree is
loaded based
on a specific query
criteria.SetFetchMode("PersonAddress", FetchMode.Join);
When I view the PersonAddress collection within the Person record, I
still see the extra fetch in the SQL profilier, and I see 2
PersonAddress records in the collection.
> > > > join mode. however you may find thatloadingeverything in a single