NHibernate Criteria Interface : Criteria is a simplified API for retrieving entities by composing NHibernate.Expression objects
Questions tagged [icriteria]
151 questions
27
votes
3 answers
NHibernate - CreateCriteria vs CreateAlias
Assuming the following scenario:
class Project{
public Job Job;
}
class Job{
public Name;
}
Assuming I want to use the Criteria API to search for all projects whose Job has the name "sumthing".
I could use the CreateAlias to create an alias…

Megacan
- 2,510
- 3
- 20
- 31
18
votes
1 answer
Lazy loading not working for many-to-one relationship when mapping to a non-key field using property-ref
I have a legacy database that I am mapping using NHibernate. The objects of concern are an Account and a list of Notification objects. The objects look like:
public class Notification
{
public virtual int Id { get; set; }
public virtual…

SteveBering
- 947
- 1
- 12
- 30
16
votes
1 answer
How do I take the "top n" using NHibernate Criteria API?
How do I take the "top n" using NHibernate Criteria API? Ideally I'd like to use detached criteria.

Ben Aston
- 53,718
- 65
- 205
- 331
15
votes
4 answers
NHibernate HQL vs CriteriaAPI vs QueryOver vs Linq. Performance
What are the performance differences between the hql and criteriaApi and QueryOver? Are there any situations where one is faster or slower than the other?
Edit: I extended the question with QueryOver and…

mynkow
- 4,408
- 4
- 38
- 65
10
votes
6 answers
NHibernate How do I query against an IList property?
I am trying to query against an IList property on one of my domain classes using NHibernate. Here is a simple example to demonstrate:
public class Demo
{
public Demo()
{
this.Tags = new List();
}
public…

JohnRudolfLewis
- 1,692
- 1
- 18
- 33
9
votes
1 answer
What's the difference between DetachedCriteria and ICriteria
These classes have some similar methods but seem to work slightly different.
What's the difference between them and when should I use each of them?

x__dos
- 1,813
- 3
- 27
- 47
9
votes
2 answers
NHibernate Query across multiple tables
I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities,
and lists the results. As a simple example, I have the following objects;
public class Cat {
public string name {get; set;}
}
public…

Dai Bok
- 3,451
- 2
- 53
- 70
9
votes
3 answers
Nhibernate Criteria: 'select max(id)...'
Can I use a Criteria to execute a t-sql command to select the max value for a column in a table?
'select @cus_id = max(id) + 1 from customers'
Ta
Ollie

AwkwardCoder
- 24,893
- 27
- 82
- 152
8
votes
7 answers
NHIbernate: Shortcut for projecting all properties?
I'm trying to generate SQL along the lines of:
SELECT
t.*,
SELECT (...)
FROM Title t
[trimmed]
using QueryOver
Title title = null;
var q = session
.QueryOver(() => title)
.Select(
Projections.Alias(Projections.Property(t…

csano
- 13,266
- 2
- 28
- 45
8
votes
2 answers
How to set more than 2 Expression in Expression.Or
I want to create a query which has more than 3-4 Expression.Or ? But Expression.Or just let me to add two Expressions inside it.
if (!string.IsNullOrEmpty(keyword))
query
.Add(Expression.Or(
…

Barbaros Alp
- 6,405
- 8
- 47
- 61
8
votes
1 answer
NHibernate - Implement "NOT IN" query using ICriteria
I've started getting to grips with NHibernate. I'm trying to perform a query that selects all records from a table but with an exclusion filter list of IDs, eg. get me all Products except these ones with these ID values.
Normally in direct T-SQL I'd…

Sunday Ironfoot
- 12,840
- 15
- 75
- 91
7
votes
1 answer
NHibernate Criteria Query - Select Distinct
I have a Person entity belongs to a person has a Country, I want to select all the distinct countries that have people in them. Easy in HQL
select distinct p.Country from Person p
How can I do this using a Criteria Query?

reach4thelasers
- 26,181
- 22
- 92
- 123
7
votes
1 answer
Projections.Conditional - How to use it?
Anyone knows how to use Projections.Conditional to produce something like "case ... when..."
The following code gives a wrong query:
IProjection isError = Projections.Conditional( Expression.Eq( "event.LogLevel", eLogLevel.Fatal.ToString( ) ),…

Caro
- 91
- 1
- 4
6
votes
2 answers
How do I select a Random Row using NHibernate's ICriteria API?
Can I select a random row using NHibernate's ICriteria API?

Andrey Selitsky
- 2,584
- 3
- 28
- 42
5
votes
2 answers
NHibernate Projections and "Having" clause
I'm using NHibernate to query my database with the criteria API. My criteria is below:
ICriteria c = Session.CreateCriteria(typeof(Transaction));
ProjectionList projections = Projections.ProjectionList();
projections.Add(Projections.Sum("Units"),…

lomaxx
- 113,627
- 57
- 144
- 179