2

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!!

hazzik
  • 13,019
  • 9
  • 47
  • 86
Miaka
  • 63
  • 5

1 Answers1

5

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.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Just out of curiousity, which one is the generic one? (I know this sounds like a stupid question, but the documentation I found, http://nhforge.org/doc/nh/en/index.html, does not explain it.) – Miaka Feb 27 '13 at 16:13
  • generic is the `session.CreateCriteria();` this should be used if possible – Radim Köhler Feb 27 '13 at 16:41