Detached criteria can be perfectly used to query associations. They are
detached because you can create them without a session (detached) and attach
them to a session later.
Try:

var crit =
DetachedCriteria.For<Car>().CreateCriteria("engine").Add(Expression.Eq("NumberOfCylinders",8));

-Markus

2009/6/17 csharp <[email protected]>

>
> Any chance castle will add some type of association criteria or query
> object so instead of using detached criteria, an association can be
> declared and queries against in instance like my example code above
> (car, engine, etc - using an association query to query the engine
> object of a car object?
>
>
>
> On Jun 17, 12:04 pm, Markus Zywitza <[email protected]> wrote:
> > I like HQL much better than Criteria, despite of the missing
> IntelliSense.
> > HQL is more powerful in regard to joins (Criteria cannot join on
> unrelated
> > entities) and gives a more compact and concise view of the actual query.
> > Only when I had to dynamically build query strings, I use Criteria
> instead.
> > -Markus
> >
> > 2009/6/17 csharp <[email protected]>
> >
> >
> >
> >
> >
> > > I have set lazy=false as well, both on classes and collection
> > > properties.
> >
> > > with my model, when i load a root 99% of the time i will be using
> > > every object under the root, so I want to make it as optimized as
> > > possible knowing i will be using the objects.
> >
> > > it looks like detached criteria is the way to go.  I believe i read
> > > that HQL came after criteria queries and is the preferred way to do
> > > things.
> >
> > > i also may have misquoted above, according to
> > >https://www.hibernate.org/315.html
> > > "HQL queries do not respect any fetch="join" defined in the mapping
> > > document"
> >
> > > I use fetch="select" though, so it looks like HQL queries would be
> > > sufficient.
> >
> > > Thanks Markus for answering both my posts :)
> >
> > > On Jun 17, 10:15 am, Markus Zywitza <[email protected]> wrote:
> > > > The FetchEnum just specifies how it is loaded, not when. For this you
> > > should
> > > > set lazy=false for all entities within the aggregate. With FetchEnum,
> you
> > > > just influence the SQL created by NHibernate, which should be
> irrelevant
> > > to
> > > > the model.
> >
> > > > -Markus
> >
> > > > 2009/6/17 csharp <[email protected]>
> >
> > > > > I am doing it this way because I am using DDD principles.  I choose
> to
> > > > > load my entire aggregate root at once, just a personal preference.
> >
> > > > > On Jun 17, 2:20 am, Markus Zywitza <[email protected]>
> wrote:
> > > > > > To be honest, I'm using AR now for 3 years, but I never specified
> the
> > > > > Fetch
> > > > > > property on any of my collections. To me, it smells a bit like
> > > premature
> > > > > > optimization. If you worry on performance, you should rather be
> picky
> > > > > about
> > > > > > when to use lazy loading and when not to use it (n+1). This can
> be
> > > done
> > > > > both
> > > > > > in HQL and Criteria.
> >
> > > > > > As for DetachedCriteria:
> >
> > > > > > ActiveRecordMediator<T> has overloads of FindAll, FindFirst and
> > > FineOne
> > > > > > taking DetachedCriteria.
> > > > > > -Markus
> >
> > > > > > 2009/6/17 csharp <[email protected]>
> >
> > > > > > > I do not want to use HQL as I read that it does not respect the
> > > > > > > FetchEnum I specify in the property attributes.
> >
> > > > > > > to query an association - random example :
> >
> > > > > > > class car
> > > > > > >  -engine
> > > > > > >  -transmission
> > > > > > >  -numberOfWheels
> > > > > > >  -etc
> >
> > > > > > > class engine
> > > > > > >  -number of cylinders
> >
> > > > > > > class transmission
> > > > > > >  -auto?
> > > > > > >  -type
> >
> > > > > > > I read that it looks like using detached criteria is the
> > > recommended
> > > > > > > approach to query properties of the engine object inside the
> car
> > > > > > > object, yet Hibernate's docs say this about detached criteria:
> >
> > > > > > > The DetachedCriteria class lets you create a query outside the
> > > scope
> > > > > > > of a session, and then later execute it using some arbitrary
> > > Session.
> >
> > > > > > > Also, they have a specific section regarding querying
> associations:
> >
> > >http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycr.
> > > > > ..
> >
> > > > > > > Does Castle have a way to query associations using ICriterion?
> >
> > > > > > > Alternatively, did i misread that HQL does not respect the
> > > FetchEnum I
> > > > > > > specify in the property attributes
> >
> > > > > > > I don't mind one way or another, just wanted to see what the
> pros
> > > and
> > > > > > > cons were. Does HQL introduce any limitations at all?- Hide
> quoted
> > > text
> > > > > -
> >
> > > > > > - Show quoted text -- Hide quoted text -
> >
> > > > - Show quoted text -- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to