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
0
votes
1 answer

Nhibernate table-per-subclass criteria on subclass ID uses key column in parent table

I using the table per subclass strategy for inheritance in my application, as described in Ayende's post here. However, when I am querying for a subclass specifically, say Company, and filtering on the Id (which I know), the resulting SQL is…
sebd
  • 572
  • 1
  • 4
  • 8
0
votes
1 answer

Querying aggregate object in NHibernate/Hibernate

I have a Domain Model for Countries and States that looks like the following(see below). I want to (with the Crieteria API or HQL) fetch all States for a specific country. I receive as a parameter the CountryCode. From what I understand in…
0
votes
1 answer

Help with removing duplicates

I have asked a similar question 6 months ago that still has not been answer or any suggestions made. Here is the problem. The code below is returning duplicate records. The actual returned record set I am working with is the Model.Product. The…
0
votes
1 answer

Using NHibernate to report a table with two sums

I have three tables: People, Purchases, Payments with 1-to-many relationships between People and Purchases, and People and Payments. I want to generate a report of People showing the sum of their Purchases and Payments. I can easily generate a…
Rob Walker
  • 46,588
  • 15
  • 99
  • 136
0
votes
1 answer

Does DetachedCriteria/ICriteria have any restriction on join depth?

Imagine I have C1, C2 and C3 classes. Suppose we can have string dummy = c1.ContainerC2.ContainerC3.Prop1. Is there any restriction that does not allow me to create an alias directly from C3 without having other classes in the criteria? For…
Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
0
votes
1 answer

Nhibernate Restrictions.In Error

Finally tracked down my error which is a result of the query. I have an nhibernate query using a Restrictions.In. Problem is once query executes if no results returned query throws error immediately. Is there another restriction that I can use. …
Troy Bryant
  • 994
  • 8
  • 29
  • 60
0
votes
1 answer

CreateCriteria, joining associations

How can I write the following SQL using CreateCriteria: SELECT sa_bec_matricula.* FROM sa_bec_matricula INNER JOIN sa_matricula ON sa_bec_matricula.sa_mtc_num = sa_matricula.sa_mtc_num INNER JOIN sa_periodo ON…
Francisco Q.
  • 177
  • 2
  • 3
  • 10
0
votes
1 answer

Create ICriterion by iterating through properties via PropertyInfo for NHibernate session

I've got a client model that has many properties like first name, last name, address, ... Via the ClientEditViewModel I can change the property values in TextBoxes. public class ClientEditViewModel : EditableViewModelBase { public int ClientID …
multi_kulti
  • 103
  • 1
  • 1
  • 5
0
votes
1 answer

How to add multiple columns inside a single GroupProperty method of Nhibernate Projections Class

I am using Visual Studio 2008. I am trying add multiple columns inside a single GroupProperty method of Nhibernate.Projections Class. But But I am failing to get the required output. I tried something like this. ICriteria Criteria =…
0
votes
1 answer

Anonymous count with nhibernate criteria?

Is it possible to create a anoynmous count with nhibernate? The below query throws the exception "No column *". I could of course add a column name, but I'd prefer not to, because if I do, I'll have to lookup column names for 95…
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
0
votes
2 answers

Get row count from unique ID's

Let's suppose that I have this simple n-n table (between people and product): //id people_id product_id 1 1 1 2 1 3 3 1 5 4 2 1 And this class (already…
0
votes
1 answer

Grails: Error while applying criteria Query

I am applying some criteria query to find the sum of columns and save the result in long format. When there is data in the table, it is working fine, but in case no match records are found, the following error is thrown: Cannot cast object 'null'…
0
votes
1 answer

Hibernate simple criteria query solving problem

I'm stuck with a very simple criteria query problem: sess .createCriteria(user.class, "user") .user_c.add(Restrictions.eq("user.status", 1)) .user_c.createAlias("user.userCategories","ucs") …
Michel
  • 9,220
  • 13
  • 44
  • 59
0
votes
1 answer

How do I query by the count of a property in nhibernate without using a detached criteria?

hey guys, I'm using NHibernate version 2.1.2.4000. The Entity class bowl { int id { get; set; } List fruits { get; set; } } The Desired (pseudo) Query var bowls = repository.where(b => b.fruits.count > 1); The Question How do I do…
andy
  • 8,775
  • 13
  • 77
  • 122
0
votes
1 answer

How do I use NHibernate criteria queries to load associations based on additional conditions

Let's say I have a Cat that has two properties: FavoriteKitten SecondFavoriteKitten These kittens are discriminated by their Rank. When loading a Cat, I want the kitten with the rank of "1" to be FavoriteKitten, and the kitten with the rank of "2"…
Mark Wilkins
  • 175
  • 7