Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference/advantages between ICriteria and ICriterion in nHibernate?

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?

like image 767
Dead account Avatar asked Aug 28 '09 09:08

Dead account


1 Answers

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.

like image 194
Frederik Gheysels Avatar answered Sep 29 '22 00:09

Frederik Gheysels