Questions tagged [nhibernate-criteria]

The NHibernate Criteria API allows performing dynamic, object oriented queries in NHibernate.

Using the criteria API is one way to perform queries in NHibernate. Its strength is on writing dynamic queries at runtime. It lacks some features compared to HQL, for instance creation of cross products and joining objects on arbitrary properties.

Related:

  • QueryOver is a successor of Criteria, which provides more type safety at compile time, but is still base on Criteria.
  • Linq To NHibernate once based on Criteria, but had been rewritten to use HQL in later versions.

References:

286 questions
23
votes
3 answers

NHibernate Criteria Restriction vs Expression

If I search for NHibernate Criteria API query examples in internet there are examples that use Restrictions and others use Expression. What are the differences between those two? For example: posts = session.CreateCriteria() …
Darius Kucinskas
  • 10,193
  • 12
  • 57
  • 79
13
votes
1 answer

NHibernate - Wrong Columns on Queries

I'm getting an intermittant problem with NHibernate where it generates a query for an entity, but replaces one of the columns with a column from completely different (and unrelated) entity. It only ever replaces a single column, and is generally…
tpither
  • 256
  • 1
  • 11
10
votes
1 answer

NHibernate - easiest way to do a LIKE search against an integer column with Criteria API?

I'm trying to do a like search against an integer column, what I need to do is actually cast the column to a varchar and then do the like search. Is this possible? what's the easiest way to do this using the Criteria API? var search =…
Jon Erickson
  • 112,242
  • 44
  • 136
  • 174
10
votes
1 answer

QueryOver statement for selecting N rows with descending DateTime order

I am trying to write QueryOver statement for selecting N rows in the descending time order. session.QueryOver().Take(10).OrderBy(x=>x.DateInserted); Unfortunately this is not at all working. Is there any way to sort it out?
navule
  • 3,212
  • 2
  • 36
  • 54
9
votes
2 answers

Querying with nHibernate where todays date is between publishDate and Expiry date

I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime The expiry date can be null so I need to allow for that. I found a couple of…
Andrew
  • 9,967
  • 10
  • 64
  • 103
9
votes
2 answers

Nhibernate QueryOver. OrderBy using strings property names.

I'm refactoring old-style query CreateCriteria() to QueryOver(). My Wcf service gets string PropertyName to order queries results. For IQueryable I use Dynamic LINQ to do such ordering, for CreateCriteria() - AddOrder(). IList result = …
Ievgen Martynov
  • 7,870
  • 8
  • 36
  • 52
7
votes
3 answers

Querying with NHibernate

I am new to NHibernate and I am trying to learn how to query my data. Below is the configuration xml. Only the recipe is shown. I want to be able to query recipes by recipetitle from keywords entered and also ingredients from ingredientname. So you…
Malcolm
  • 12,524
  • 28
  • 89
  • 125
6
votes
6 answers

Nhibernate QueryOver don't get latest database changes

I am trying get a record updated from database with QueryOver. My code initially creates an entity and saves in database, then the same record is updated on database externally( from other program, manually or the same program running in other…
Carlos
  • 456
  • 2
  • 7
  • 21
6
votes
2 answers

Nhibernate Projection over nested nested properties

I have domain class location public abstract class BaseEntity where T: struct { public virtual T Id { get; set; } public virtual bool Equals(BaseEntity other) } public class Location : BaseEntity { …
Techmaster
  • 1,032
  • 2
  • 12
  • 26
5
votes
1 answer

Linq to NHibernate query comparing enum mapped as integer succeeds, but fails as equivalent criteria query

I'm querying for ProductRisk, which contains a Status property, where Status is an enum. Here's the mapping for ProductRisk: public class ProductRiskMap : ClassMap { public ProductRiskMap() { …
Vish
  • 453
  • 6
  • 18
5
votes
2 answers

How to do multiple joins with NHibernate Criteria API

I have the following data model: Page - Id // Pk - Type // int Section - Id // Pk - Page // Fk Comment - Id // Pk - Section // Fk - Date // DateTime I'm trying to query all comments that are associated with a certain Page…
5
votes
2 answers

How do I express this LINQ query using the NHibernate ICriteria API?

My current project is using NHibernate 3.0b1 and the NHibernate.Linq.Query() API. I'm pretty fluent in LINQ, but I have absolutely no experience with HQL or the ICriteria API. One of my queries isn't supported by the IQueryable API, so I presume…
Brant Bobby
  • 14,956
  • 14
  • 78
  • 115
5
votes
2 answers

NHibernate AliasToBean transformer associations

I'm trying to use the following statement to get an entity with the fields I'm after: retVal = session.CreateCriteria(typeof(MyEntity)) .CreateAlias("MyEntityProperty", "MyEntityProperty") …
tomunderhill
  • 301
  • 1
  • 4
  • 11
5
votes
1 answer

Set TimeOut Expired in NHibernate

I have a stored procedure in sql server 2008 R2 which was working fine, but suddenly it throws an exception of TimeOut Expiration. BmDaoSession.CreateSQLQuery("exec SP_Name @Param1 = '" + clientCode + "', @Param2 ='" + existingDatabase + "',…
user3124690
  • 413
  • 1
  • 12
  • 25
5
votes
1 answer

Nhibernate query for items that have a Dictionary Property containing value

I need a way to query in Nhibernate for items that have a Dictionary Property containing value. Assume: public class Item { public virtual IDictionary DictionaryProperty {get; set;} } and mapping: public ItemMap() { …
1
2 3
19 20