views:

974

answers:

1

Bit of a newbie question as Im getting started with nHibernate.

What's the difference between NHibernate.Criterion.ICriterion and NHibernate.ICriteria classes and which should I use for simple "where field=value" type filtering?

+7  A: 

An ICriteria is used to represent a query. You can add ICriterions to this ICriteria to express filters.

For instance:

ICriteria crit = session.CreateCriteria (typeof(Person));

crit.Add (NHibernate.Criterion.Expression.Eq("Name", "somename"));

Or, as the documentation states:

ICriterion: An object oriented representation of a query criterion that may be used as a constraint in an ICriteria query

ICriteria: a simplified API for retrieving entities by composing NHibernate.Criterion.Expression objects.

Frederik Gheysels
+1 Thanks. Am just getting a little overloaded at the mo'. Your example makes it clear now.
Dead account