These classes have some similar methods but seem to work slightly different.
What's the difference between them and when should I use each of them?
detachedcriteriaicriterianhibernate
These classes have some similar methods but seem to work slightly different.
What's the difference between them and when should I use each of them?
Best Answer
Detached criteria can be built up without reference to an
ISession
. You can later take that criteria and apply it to anISession
to get an executableICriteria
.Use
ICriteria
when you have a session.Use
DetachedCriteria
when you're not sure against what session the query will be executed.Note that
DetachedCriteria
does not implementICriteria
-- they are not interchangeable. You must always calldetachedCriteria.GetExecutableCriteria(session)
to get anICriteria
instance.