Using CriteriaQueries
In the last chapter, we fetched our entities by their Id
. In this recipe, we'll show you a few basic criteria queries to fetch entities by other properties.
Getting ready
Complete the Getting Ready section at the beginning of this chapter.
How to do it…
- Add a new folder named
QueryByCriteria
to the project. - Add a new class
CriteriaQueries
to the folder:using System.Collections.Generic; using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Criterion; using NHibernate.SqlCommand; namespace QueryRecipes.QueryByCriteria { public class CriteriaQueries : IQueries { private readonly ISession _session; public CriteriaQueries(ISession session) { _session = session; } public IEnumerable<Movie> ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.