I've seen both formats in different examples, tutorials, blogs, etc, but for the life of me, I cannot find an explanation for the difference. What is the difference between
ICriteria crit = session.CreateCriteria(typeof(Cat));
and
ICriteria crit = session.CreateCriteria<Cat>();
When do I use one and when do I use the other?
An example of a tutorial using session.CreateCriteria(typeof(Cat)) can be found at http://nhibernate.info/doc/nh/en/index.html#quickstart
An example of a tutorial using session.CreateCriteria() can be found at http://ayende.com/blog/4023/nhibernate-queries-examples (table Blog instead of Cat)
Thanks so much!!
There is no difference. You can/should use the generic one if possible, and non-generic if you have access only to a Type instance (some reflection).
The non-generic is part of NHibernate from the moment when it was imported from Java Hibernate
.
The generic was added in the Build 2.1.0.Alpha1
release.
But because the result is non-generic ICriteria
(in comparison with result of the QueryOver<T>()
) it is just a syntactic sugar.