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

1

5

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?

Wojcik answered 28/8, 2009 at 9:35 Comment(0)
S
14

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.

Schrimsher answered 28/8, 2009 at 10:13 Comment(1)
+1 Thanks. Am just getting a little overloaded at the mo'. Your example makes it clear now.Wojcik

© 2022 - 2024 — McMap. All rights reserved.